Я сделал радиогруппу и внутри нее я сделал две линейные макеты, и в каждой линейной компоновке я добавил две переключатели.Несколько кнопок радиосвязи выбрано
Но проблема в том, что при запуске приложения несколько переключателей выбираются i.e. они не действуют взаимоисключающими.
Ниже мой XML-файл
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_simple_maths_game"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.root.mysimplemathsgame.SimpleMathsGame" android:background="#000"
android:orientation="vertical" android:baselineAligned="false">
<LinearLayout
android:layout_weight="0.4" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="0dp">
<TextView
android:text="@string/mytext" android:id="@+id/tvText"
android:layout_width="wrap_content" android:layout_height="0dp"
android:layout_weight="0.87" android:textColor="#fff"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:padding="20dp"
android:gravity="center_vertical" android:layout_gravity="center_vertical"
android:textSize="32sp" />
<LinearLayout
android:layout_weight="1" android:background="#fff"
android:layout_width="match_parent" android:layout_height="0dp"
android:orientation="horizontal">
<RadioGroup
android:paddingLeft="30dp" android:id="@+id/rgOptions"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:layout_weight="1" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="0dp">
<RadioButton
android:layout_weight="1" android:textColor="#000"
android:id="@+id/rb1" android:text="@string/answer1"
android:layout_width="0dp" android:layout_height="match_parent" />
<RadioButton
android:layout_weight="1" android:textColor="#000"
android:id="@+id/rb2" android:text="@string/answer2"
android:layout_width="0dp" android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_weight="1" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="0dp">
<RadioButton
android:textColor="#000"
android:layout_weight="1" android:layout_gravity="start"
android:id="@+id/rb3" android:text="@string/answer3"
android:layout_width="0dp" android:layout_height="match_parent" />
<RadioButton
android:textColor="#000"
android:layout_weight="1" android:layout_gravity="end"
android:id="@+id/rb4" android:text="@string/answer4"
android:layout_width="0dp" android:layout_height="match_parent" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_weight="1"
android:text="@string/end" android:id="@+id/bEnd" android:layout_gravity="center_horizontal"
android:layout_width="match_content" android:layout_height="wrap_content" />
</LinearLayout>
я думаю, что это потому, что ваша кнопка обернута линейной компоновки. попробуйте разместить радиообъект прямо внутри радиогруппы и посмотреть, работает ли он – firmanslash
Возможный дубликат [Как сгруппировать RadioButton из разных LinearLayouts?] (http://stackoverflow.com/questions/10461005/how-to-group-radiobutton-from-different -linearlayouts) – jamesjaya
радиогруппа может содержать только радиокнопки, если вы вставляете в нее макет и переключатели в этом макете, это не будет работать, просто удалите макет и сделайте отдельную радиогруппу и поместите свои радиокнопки внутри этой радиогруппы –