我在程序中动态的添加radiobutton,但是遇到个问题就是,当有很多歌radiobutton时,我想换行添加,也就是说限制每行的radiobutton个数。请问我该用什么方法换行呢!我的方法没有起到换行的作用。
 我的代码如下: for(int n=1;n<9;n++)
{
RadioButton radioButton = new RadioButton(this);
radioButton.setWidth(80);
radioButton.setHeight(40);
radioButton.setText("孙悟空");
radioButton.setTextColor(Color.BLACK);
radioButton.setTextSize(14.0f);
if(n%3==0)
{
System.out.println("\n");
}
radiogroup.addView(radioButton);
}

解决方案 »

  1.   

    设置RadioButton控件的大小,填满父控件的一行后会自动换行。
      

  2.   

    设置RadioButton控件的大小刚才少打了个字。 如果父控件的宽只能装下2个按钮的话,填满它后就会换行了。
      

  3.   

    我知道,我之前就是设置父控件radiogroup的宽度,也设置了radiobutton的宽度,不起作用!纠结啊
      

  4.   


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout androidrientation="horizontal"
    android:layout_width="match_parent" android:layout_height="wrap_content">
    <RadioButton android:text="01" android:id="@+id/radioButton1"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
    <RadioButton android:text="02" android:id="@+id/radioButton2"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
    </LinearLayout> <LinearLayout androidrientation="horizontal"
    android:layout_width="match_parent" android:layout_height="wrap_content">
    <RadioButton android:text="03" android:id="@+id/radioButton3"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
    <RadioButton android:text="04" android:id="@+id/radioButton4"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
    </LinearLayout>
    </LinearLayout>只是思路 你看看吧。