Android 更改单选按钮的位置
我可以把单选按钮的位置从左改右吗。我的意思是绿色的选择按钮将在右边,文本在左边。可能吗?(默认情况下,按钮向左,文本向右)应该可以使用getCompoundDrawables()和setCompoundDrawables()来重新排列文本周围的drawables 更进一步,也许您可以基于复选框实现自己的CheckBoxRight小部件,该小部件在调用super.onDraw()后在onDraw()方法中实现了这一点Android 更改单选按钮的位置,android,android-layout,android-button,android-checkbox,Android,Android Layout,Android Button,Android Checkbox,我可以把单选按钮的位置从左改右吗。我的意思是绿色的选择按钮将在右边,文本在左边。可能吗?(默认情况下,按钮向左,文本向右)应该可以使用getCompoundDrawables()和setCompoundDrawables()来重新排列文本周围的drawables 更进一步,也许您可以基于复选框实现自己的CheckBoxRight小部件,该小部件在调用super.onDraw()后在onDraw()方法中实现了这一点 最后一种选择是直接从TextView构建您自己的小部件,并在通过onClick(
最后一种选择是直接从TextView构建您自己的小部件,并在通过onClick()事件处理程序维护内部状态后适当地设置CompoundDrawables()。您可以构建自己的自定义小部件,如果您不熟悉这样做,这可能会让人望而生畏。或者你可以做我最喜欢的工作 将单选按钮当作常规按钮处理--不要使用RadioGroup功能。现在您必须手动控制检查。通过删除RadioGroup,您可以随意创建您想要的布局 下面是一个示例xml布局,它在TableLayout中使用单选按钮,每个按钮的左侧有文本,右侧有图像:
<?xml version="1.0" encoding="utf-8"?>
}
请注意,我希望用户通过选择文本、图片或按钮本身来选择RadioButton。所以我把整个桌子列都做成了可点击的对象
希望这有帮助 您可能需要为此创建自己的单选按钮。请参阅。
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/row_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 1" />
<RadioButton
android:id="@+id/rb_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pretty_pic_1" />
</TableRow>
<TableRow
android:id="@+id/row_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 2" />
<RadioButton
android:id="@+id/rb_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pretty_pic_3" />
</TableRow>
<TableRow
android:id="@+id/row_3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button 3" />
<RadioButton
android:id="@+id/rb_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pretty_pic_3" />
</TableRow>
</TableLayout>
class FooActivity extends Activity {
RadioButton m_rb1, m_rb2;
TableRow m_row1, m_row2;
@Override
protected void onCreate(Bundle savedInstanceState) {
m_rb1 = (RadioButton) findViewById(R.id.rb1);
m_rb2 = (RadioButton) findViewById(R.id.rb2);
m_row1 = (TableRow) findViewById(R.id.row_1);
m_row1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_rb1.setChecked(true);
m_rb2.setChecked(false);
}
});
m_row2 = (TableRow) findViewById(R.id.row_2);
m_row2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
m_rb1.setChecked(false);
m_rb2.setChecked(true);
}
});
}