简体   繁体   English

如何设置重力位置到父母的右下角?

[英]How to set gravity position to bottom right of parent?

I am adding button in FrameLayout at run time, that I want to set at bottom|right of parent. 我要在运行时在FrameLayout中添加按钮,我想将其设置在父对象的右下角。

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 在您的framelayout内部添加相对布局,并在该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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM