【发布时间】:2015-08-22 20:23:02
【问题描述】:
我正在尝试为小孩子制作一个数学应用程序。还有一种活动可以自定义数学问题的设置。 (位数,+ 或 -,是否启用计时器等)我正在做位数部分。这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/customize_menu"
android:layout_weight="9">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/digit_text"
android:textSize="@dimen/customize_menu_title"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="@dimen/customize_menu_radio"
android:layout_marginLeft="@dimen/radio_button_spacing"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:textSize="@dimen/customize_menu_radio"
android:layout_marginLeft="@dimen/radio_button_spacing"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:textSize="@dimen/customize_menu_radio"
android:layout_marginLeft="@dimen/radio_button_spacing"/>
</RadioGroup>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/button_trophies"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/button_start"/>
</LinearLayout>
</LinearLayout>
如您所见,我将带有文本“2”的单选按钮设置为默认选中。但是,当我运行应用程序并单击单选按钮“3”时,单选按钮“2”和“3”都被选中!然后我尝试单击单选按钮“1”,现在只选中单选按钮“1”和“2”。换句话说,无论我按下什么单选按钮,单选按钮“2”都会被选中。但这肯定不是单选按钮的工作方式,对吧?
问题:如何在不更改单选按钮“2”默认选中的事实的情况下解决此问题?他们为什么会有这种行为?
【问题讨论】:
标签: android radio-button android-xml