7

这与相关帖子中提到的问题相似,但我认为这足以引起自己的问题。它是这样的:

通过将单选按钮的按钮属性设置为 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);

这是我的示例,即使我将可绘制按钮设置为空,单选圆仍然出现。

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

无线电圈消失了,但文本没有进入无线电圈应该在的区域。这里有一些 ascii 艺术来展示它的作用:

setButtonDrawable(null): (O = 单选圆)

-------------------
| O  One | O  Two |
-------------------

setButtonDrawable(android.R.id.empty):

-------------------
|    One |    Two |
-------------------

我尝试设置文本重力等以使文本进入那个空白空间,但似乎“无线电圈”仍然存在,但它只是不可见。

对我的问题的任何帮助将不胜感激。谢谢。

4

1 回答 1

1

我看到你已经解决了这个问题,但我只是想知道你是否尝试过使用:setVisibility(View.GONE); 我认为这应该可以。

于 2011-05-30T07:23:59.817 回答