请帮我在RelativeLayout
动态下添加RadioButton
(我必须在课堂上创建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怎么样?
答案 0 :(得分:0)
我不确定我是否理解你。请检查并给我反馈。谢谢!
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);