0

I am adding button in FrameLayout at run time, that I want to set at bottom|right of parent.

LayoutParams lp = new LayoutParams(android.widget.FrameLayout.LayoutParams.WRAP_CONTENT, 
                android.widget.FrameLayout.LayoutParams.WRAP_CONTENT);

        lp.gravity = **Gravity.RIGHT**; 
        mSelf.setLayoutParams(lp);

How can I do it, any suggestion?

CoDe
  • 11,056
  • 14
  • 90
  • 197

2 Answers2

1

Add a relative layout inside of your framelayout and add components in that relativelayout
EDIT with sample

FrameLayout fr = ..... // get your layout here.
RelativeLayout mRel =  new RelativeLayout(your_activity_context);
RelativeLayout.LayoutParams mParams = mRel.getLayoutParams();
Button mBtn = new Button(this); // Component you want to add at BOTTOM RIGHT
mParams.addRule(RelativeLayout.LayoutParams.ALIGN_PARENT_BOTTOM | RelativeLayout.LayoutParams.ALIGN_PARENT_RIGHT);
mBtn.setLayoutParams(mParams);
mRel.add(mBtn);
fr.add(mRel);

Note :- There will be some minor change in the code if you add this code in your activity. because I wrote this here only. Not tested. But this should work.

johntheripp3r
  • 989
  • 6
  • 15
0

Try this code.It may help you.

RelativeLayout relativeLayout = findViewById(R.id.your_relative_layout);
mVideo = new VideoView(this); 
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); // or wrap_content
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
relativeLayout.addView(mVideo , layoutParams);
Dinesh Kumar
  • 1,173
  • 7
  • 19
  • 30
  • dear, in my case parent view is FrameLayout, I already have some other component child in that. So is it possible to perform same direct between Parent(FramLayout) and Child(ImageButton). – CoDe Oct 24 '13 at 06:49