これは、関連する投稿で言及されているものと同様の問題ですが、独自の質問を得るのに十分異なると思いました。ここに行きます:
次のように、ラジオボタンのボタン属性をnullに設定することにより、xmlでラジオボタンを宣言するときに、「ラジオサークル」を問題なく非表示にすることができました。
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:background="@drawable/radio_button_selector"
android:button="@null"/>
しかし、ラジオボタンを動的に宣言しようとすると、これを行ってもラジオサークルを消すことができません:
myRadioButton.setButtonDrawable(null);
これが私の例で、ドローアブル ボタンを null に設定しても、ラジオ サークルは引き続き表示されます。
RadioGroup myRadioGroup = (RadioGroup)findViewById(R.id.myRadioGroup);
for (int i = 0; i < arrayListOfRadioButtonStringNames.size(); i++)
{
RadioButton myRadioButton = new RadioButton(this);
myRadioButton.setText(arrayListOfRadioButtonStringNames.get(i));
myRadioButton.setButtonDrawable(null);
myRadioButton.setBackgroundResource(R.drawable.radio_button_selector);
myRadioGroup.addView(myRadioButton);
}
myRadioGroup.invalidate();
代わりに、次のようにボタン ドローアブルを空に設定すると:
myRadioButton.setButtonDrawable(android.R.id.empty);
ラジオ サークルは消えますが、ラジオ サークルがあるべき領域にテキストが入りません。これが何をするかを示すアスキーアートです:
setButtonDrawable(null): (O = ラジオ サークル)
-------------------
| O One | O Two |
-------------------
setButtonDrawable(android.R.id.empty):
-------------------
| One | Two |
-------------------
テキストのグラビティなどを設定して、その空のスペースにテキストを配置しようとしましたが、「ラジオサークル」はまだそこにあるようですが、表示されていません。
私の問題について何か助けていただければ幸いです。ありがとう。