【发布时间】:2018-02-24 12:21:51
【问题描述】:
我在单选组中使用单选按钮 - 效果很好
<RadioGroup
android:layout_below="@id/textview_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="30dp"
android:id="@+id/radgrp">
<RadioButton
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:textSize="20dp"
android:layout_weight="1"
android:id="@+id/radiobutton_1"
android:text="option"
android:textStyle="italic"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:textSize="20dp"
android:layout_weight="1"
android:id="@+id/radiobutton_2"
android:text="option"
android:textStyle="italic"/>
<RadioButton
android:id="@+id/radiobutton_3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="option"
android:textSize="20dp"
android:textStyle="italic"
/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="0dp"
android:textSize="20dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:id="@+id/radiobutton_4"
android:text="option"/>
</RadioGroup>
但是,每当我尝试通过在卡片视图周围环绕单选按钮来使用某些样式时-单选组失去了所有功能.. 我说的是我使用以下代码时的情况-
<RadioGroup
android:layout_below="@id/textview_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="30dp"
android:id="@+id/radgrp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="20dp"
android:layout_weight="1"
android:id="@+id/radiobutton_1"
android:text="option"
android:textStyle="italic"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="20dp"
android:layout_weight="1"
android:id="@+id/radiobutton_2"
android:text="option"
android:textStyle="italic"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radiobutton_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="option"
android:textSize="20dp"
android:textStyle="italic"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="10dp"
app:cardCornerRadius="20dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:id="@+id/radiobutton_4"
android:text="option"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</RadioGroup>
现在的问题是我如何通过给单选按钮以像 cardview 一样的航空感觉来设置单选按钮的样式。因为上面的代码在单选组的功能中出现问题(错误包括 - clearCheck() 方法无效以及多次检查发生..等)。
请帮助我以我想要的方式设置单选按钮的样式(即为每个单选按钮提供卡片般的感觉)
【问题讨论】:
-
而不是在卡片视图中放置单选按钮尝试为您提供单选按钮的背景
-
当他们是radiogroup的时候不要在cardview里面添加radiobutton。看看如何自定义radio button。
标签: android xml android-layout user-interface android-cardview