ave*_*eyD 6 android dynamic radio-group radio-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"/>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试动态地声明单选按钮时,即使我这样做,也无法让无线电圈消失:
myRadioButton.setButtonDrawable(null);
Run Code Online (Sandbox Code Playgroud)
这是我的例子,即使我将按钮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();
Run Code Online (Sandbox Code Playgroud)
如果我改为将drawable设置为空,如下所示:
myRadioButton.setButtonDrawable(android.R.id.empty);
Run Code Online (Sandbox Code Playgroud)
无线电圈消失了,但文本没有进入无线电圈所在的区域.这里有一些ascii艺术来展示它的作用:
setButtonDrawable(null):( O =无线电圈)
-------------------
| O One | O Two |
-------------------
Run Code Online (Sandbox Code Playgroud)
setButtonDrawable(android.R.id.empty):
-------------------
| One | Two |
-------------------
Run Code Online (Sandbox Code Playgroud)
我已经尝试设置文本引力等,以使文本进入那个空白区域,但似乎"无线电圈"仍然存在,但它只是不可见.
任何有关我的问题的帮助将不胜感激.谢谢.
| 归档时间: |
|
| 查看次数: |
5503 次 |
| 最近记录: |