Android dynamic RadioGroup/RadioButtons作为平面按钮

Android dynamic RadioGroup/RadioButtons作为平面按钮,android,dynamic,radio-button,radio-group,Android,Dynamic,Radio Button,Radio Group,这是一个与a中提到的问题类似的问题,但我认为它的不同足以引出它自己的问题。下面是: 通过将单选按钮的button属性设置为null(如下所示),我能够在xml中声明单选按钮时让“单选圈”消失,没有问题: <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="One" android:b

这是一个与a中提到的问题类似的问题,但我认为它的不同足以引出它自己的问题。下面是:

通过将单选按钮的button属性设置为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(android.R.id.empty);
这是我的示例,即使我将按钮drawable设置为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();
广播圈消失了,但文本没有进入广播圈应该位于的区域。下面是一些ascii艺术来展示它的功能:

setButtonDrawable(空):(O=无线电圆圈)

setButtonDrawable(android.R.id.empty):

我试着设置文本重力等,让文本进入那个空白区域,但似乎“无线电圈”仍然存在,但它只是不可见


在我的问题上任何帮助都将不胜感激。谢谢。

我看到您已经解决了这个问题,但我想知道您是否尝试过使用:
setVisibility(View.GONE)

我认为这应该行得通。

实际上,将按钮设置为可拖动到android的空资源是可行的。。。我所要做的就是:myRadioButton.setButtonDrawable(android.R.id.empty);myRadioButton.setPadding(5,0,5,0);然后它(在Galaxy选项卡上)工作了。。。但是:由于某种原因,当我在Xoom上运行它时,它崩溃并给我一个“android.content.res.Resources$NotFoundException:File from drawable resource Id#uuuuuuuuuuuuuuuuuo”为什么Xoom不能访问android.R.Id.empty资源,但Galaxy选项卡可以?修复了这个问题。请看这里的帖子:我还没有机会尝试一下,但这不会让整个单选按钮消失吗?我只想让单选按钮里面的“点”消失。不过谢谢你的建议。:)啊,是的,没错。错过了那个:)
myRadioButton.setButtonDrawable(android.R.id.empty);
-------------------
| O  One | O  Two |
-------------------
-------------------
|    One |    Two |
-------------------