lom*_*mza 1 xml android button android-layout
基本上,我有这种布局结构:<RelativeLayout> <RelativeLayout> <TextView /> </RelativeLayout> <ScrollView> <RelativeLayout> ... </RelativeLayout> </ScrollView> </RelativeLayout>我想以编程方式添加按钮.这个按钮应该在里面<RelativeLayout>,里面是<ScrollView>.另外,我需要它与底部和CENTER_VERTICAL对齐.我真的很感激任何提示/示例;)谢谢!PS尽管在stackoverflow上有很多类似的问题,但没有一个答案对我有帮助......
首先,您需要为XML中的相对布局提供ID : android:id="@+id/myLayout". 然后在Java代码中:
Button b = new Button(this);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rl.addRule(RelativeLayout.ALIGN_BOTTOM);
b.setLayoutParams(rl);
((RelativeLayout) findViewById(R.id.myLayout)).addView(b);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3802 次 |
| 最近记录: |