RadioGroup 只能直接包含 RadioButton,需在每個 RadioButton 下方顯示 TextView 說明。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rb1"
android:text="Description for option 1" />
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv1"
android:text="Option 2" />
<TextView
android:layout_below="@id/rb2"
android:text="Description for option 2" />
</RelativeLayout>
RadioButton rb1 = findViewById(R.id.rb1), rb2 = findViewById(R.id.rb2);
rb1.setOnCheckedChangeListener((btn, checked) -> {
if (checked) rb2.setChecked(false);
});
rb2.setOnCheckedChangeListener((btn, checked) -> {
if (checked) rb1.setChecked(false);
});