请帮助我在 RadioButton
下动态添加 RelativeLayout
(我必须在类中创建 RelativeLayout
和 RadioButton
)。
类似这样的事情:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioButton3"
android:text="RadioButton" />
<RelativeLayout
android:id="@+id/relativeLayout2"
android:layout_below="@+id/radioButton3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</LinearLayout>
要查看我可以写:
myLayout.addView(myView, layoutParams);
但是 ViewGroup 怎么样?
最佳答案
我不确定我是否理解你。请检查并给我反馈。谢谢!
LinearLayout mLayout = (LinearLayout) findViewById(R.id.myLayout);
LayoutParams p = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
RadioButton mRadioButton = new RadioButton(this);
mRadioButton.setLayoutParams(p);
mLayout.addView(mRadioButton);
p = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
RelativeLayout mRelativeLayout = new RelativeLayout(this);
mRelativeLayout.setLayoutParams(p);
mLayout.addView(mRelativeLayout);
关于java - 如何动态添加某个元素下方的相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28822483/