您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關Android中怎么使用RadioGroup實現多行顯示效果 ,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
1、布局如下:
<RadioGroup android:id="@+id/rg_manhole_state_one" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_toRightOf="@id/tv_manhole_state" android:orientation="horizontal" android:paddingTop="@dimen/padding_5"> <RadioButton android:id="@+id/rb_intact" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@null" android:drawableLeft="@drawable/bg_radiobutten" android:drawablePadding="@dimen/padding_10" android:text="@string/intact" android:textColor="@color/white" android:textSize="@dimen/small_size" /> <RadioButton android:id="@+id/rb_lose" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:button="@null" android:drawableLeft="@drawable/bg_radiobutten" android:drawablePadding="@dimen/padding_10" android:text="@string/lose" android:textColor="@color/white" android:textSize="@dimen/small_size" /> <RadioButton android:id="@+id/rb_sunken" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:button="@null" android:drawableLeft="@drawable/bg_radiobutten" android:drawablePadding="@dimen/padding_10" android:text="@string/sunken" android:textColor="@color/white" android:textSize="@dimen/small_size" /> </RadioGroup> <RadioGroup android:id="@+id/rg_manhole_state_two" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/padding_100" android:layout_marginTop="5dp" android:orientation="horizontal" android:paddingTop="@dimen/padding_5"> <RadioButton android:id="@+id/rb_occupation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@null" android:drawableLeft="@drawable/bg_radiobutten" android:drawablePadding="@dimen/padding_10" android:text="@string/occupation" android:textColor="@color/white" android:textSize="@dimen/small_size" /> <RadioButton android:id="@+id/rb_damage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:button="@null" android:drawableLeft="@drawable/bg_radiobutten" android:drawablePadding="@dimen/padding_10" android:text="@string/damage" android:textColor="@color/white" android:textSize="@dimen/small_size" /> <RadioButton android:id="@+id/rb_heave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:button="@null" android:drawableLeft="@drawable/bg_radiobutten" android:drawablePadding="@dimen/padding_10" android:text="@string/heave" android:textColor="@color/white" android:textSize="@dimen/small_size" /> </RadioGroup>
2、具體操作如下:
聲明控件:
@InjectView(R.id.rg_manhole_state_one) RadioGroup rgManholeStateOne; @InjectView(R.id.rg_manhole_state_two) RadioGroup rgManholeStateTwo;
設置監聽:
rgManholeStateOne.setOnCheckedChangeListener(new OnMyManholeStateOneCheckedChangeListener()); rgManholeStateTwo.setOnCheckedChangeListener(new OnMyManholeStateTwoCheckedChangeListener());
實現單選:
private class OnMyManholeStateOneCheckedChangeListener implements RadioGroup.OnCheckedChangeListener { @Override public void onCheckedChanged(RadioGroup radioGroup, int position) { switch (position) { case R.id.rb_intact: if (rbIntact.isChecked()) rgManholeStateTwo.clearCheck(); break; case R.id.rb_lose: if (rbLose.isChecked()) rgManholeStateTwo.clearCheck(); break; case R.id.rb_sunken: if (rbSunken.isChecked()) rgManholeStateTwo.clearCheck(); break; } } } private class OnMyManholeStateTwoCheckedChangeListener implements RadioGroup.OnCheckedChangeListener { @Override public void onCheckedChanged(RadioGroup radioGroup, int position) { switch (position) { case R.id.rb_occupation: if (rbOccupation.isChecked()) rgManholeStateOne.clearCheck(); break; case R.id.rb_damage: if (rbDamage.isChecked()) rgManholeStateOne.clearCheck(); break; case R.id.rb_heave: if (rbHeave.isChecked()) rgManholeStateOne.clearCheck(); break; } } }
上述就是小編為大家分享的Android中怎么使用RadioGroup實現多行顯示效果 了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。