3

私のレイアウトは次のようになります

    <?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="wrap_content">
        <TextView android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:textStyle="bold" 
            android:text="Please select the restaurant you want to rate: " />

        <RadioGroup android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/SelectRestaurant">

         </RadioGroup>
         <Button android:layout_width="100px"
         android:layout_height="wrap_content" 
         android:text="Rate it" 
         android:id="@+id/submitSelection"/>
</LinearLayout>

Javaファイルのラジオグループにラジオボタンを追加すると、ラジオボタンが重なり合って送信ボタンがなくなります。ラジオボタンがビューの他の要素をオーバーライドしていると思います。他の要素を失うことなく、これらのラジオ ボタンを動的に追加するにはどうすればよいですか。

Java コードは次のようになります。

setContentView(R.layout.submit_select);
        RadioGroup radioGroup = (RadioGroup)findViewById(R.id.SelectRestaurant);
        for (String restaurant : restaurants) {
            RadioButton radioButton = new RadioButton(getBaseContext());
            radioButton.setText(restaurant);
            radioGroup.addView(radioButton);
        }
        radioGroup.invalidate();
        dismissDialog(DIALOG_SUBMIT_ID);
        rateItButton = (Button) findViewById(R.id.submitSelection);
        rateItButton.setOnClickListener(this);
4

1 に答える 1

2

幅と高さの WRAP_CONTENT を使用してレイアウト パラメータを作成し、ボタンをグループに追加するときに layoutParams を追加してみてください。

radiogroup.addView(newRadioButton, layoutParams);
于 2011-09-02T17:07:00.470 に答える