如何在某些元素下方动态添加相对布局

How to add relative Layout below some element dynamically

请帮我在RadioButton下面动态添加一个RelativeLayout(我必须在class中创建RelativeLayoutRadioButton)。

像这样:

<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);