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?
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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.