0

我在运行时在 FrameLayout 中添加按钮,我想将其设置在父级的右下角。

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

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

我该怎么做,有什么建议吗?

4

2 回答 2

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.

于 2013-10-23T13:43:56.757 回答
0

试试这个代码。它可以帮助你。

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);
于 2013-10-23T13:44:25.963 回答