本文主要是介绍RadioButton 多行 多列显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
布局:
<RadioGroupandroid:id="@+id/rg_first"style="@style/rg_style"android:orientation="horizontal"><RadioButtonandroid:id="@+id/pay_issue"style="@style/rg_rb_style"android:text="@string/pay_issue" /><RadioButtonandroid:id="@+id/cannot_play"style="@style/rg_rb_style"android:text="@string/cannot_play" /></RadioGroup><RadioGroupandroid:id="@+id/rg_second"style="@style/rg_style"android:orientation="horizontal"><RadioButtonandroid:id="@+id/force_closure"style="@style/rg_rb_style"android:text="@string/force_closure" /><RadioButtonandroid:id="@+id/play_pause"style="@style/rg_rb_style"android:text="@string/play_pause" /></RadioGroup><RadioGroupandroid:id="@+id/rg_third"style="@style/rg_style"android:orientation="horizontal"><RadioButtonandroid:id="@+id/other_issues"style="@style/rg_rb_style"android:text="@string/other_issues" /></RadioGroup>
Java:
public class FeedBackActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener{private RadioGroup firstRG;private RadioGroup secondRG;private RadioGroup thirdRG;public static Intent getFeedBackActivityIntent(Context context){Intent feedBackIntent = new Intent(context, FeedBackActivity.class);return feedBackIntent;}@Overrideprotected int getLayoutId() {return R.layout.aty_feed_back;}@Overrideprotected void afterCreate() {firstRG = (RadioGroup) findViewById(R.id.rg_first);secondRG = (RadioGroup) findViewById(R.id.rg_second);thirdRG = (RadioGroup) findViewById(R.id.rg_third);firstRG.setOnCheckedChangeListener(this);secondRG.setOnCheckedChangeListener(this);thirdRG.setOnCheckedChangeListener(this);}@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {if(group != null && checkedId>0){if(group == firstRG){secondRG.clearCheck();thirdRG.clearCheck();}else if(group == secondRG){firstRG.clearCheck();thirdRG.clearCheck();}else if(group == thirdRG){firstRG.clearCheck();secondRG.clearCheck();}group.check(checkedId);}}
}
color.xml:
<style name="rg_style"><item name="android:layout_width">match_parent</item><item name="android:layout_height">wrap_content</item></style><style name="rg_rb_style"><item name="android:layout_width">wrap_content</item><item name="android:layout_height">wrap_content</item><item name="android:layout_weight">1</item></style>
效果图:
这篇关于RadioButton 多行 多列显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!