如果我有一个带7个radiobutton的radiogroup,我希望它们像这样对齐:
button2 button5
button1 button3 button6
button4 button7
有没有办法我可以用一个RadioGroup做上面的事情(即使按钮1在第一行也没问题,但这是我正在寻找的一般布局)
请帮忙
由于
答案 0 :(得分:0)
您可以根据此http://developer.android.com/reference/android/widget/RadioGroup.OnCheckedChangeListener.html:
实施自己的按钮处理逻辑public class RadioButtonHandler implements RadioButton.OnCheckedChangeListener {
private CompoundButton currentlyCheckedButton = null;
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
if (isChecked) {
currentlyCheckedButton .setChecked(false);
currentlyCheckedButton = button;
}
}
public void addButton(RadioButton button) {
// if this is the first button, set it as the current button
if (currentlyCheckedButton == null) {
currentlyCheckedButton = button;
}
button.setOnCheckedChangeListener(this);
}
public CompoundButton getCheckedRadioButton() {
return currentlyCheckedButton ;
}
}
实例化此类并为类应控制的每个按钮调用addButton。然后,您可以在所需的任何视图组中布置按钮。为onCheckChanged回调添加额外的逻辑或调用getCheckedRadioButton,它将返回对当前选中按钮的引用。
[编辑]修正了错字= getCheckedButton - > getCheckedRadioButton