Abnormal behavior with RadioButton
I am using RadioButton
in my layout. Where I presented the background RadioButton
. Below is the code
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/rb_spain"
android:id="@+id/am_rb_spain" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/rb_germany"
android:layout_marginLeft="@dimen/margin_15"
android:layout_marginRight="@dimen/margin_15"
android:id="@+id/am_rb_german" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/rb_english"
android:id="@+id/am_rb_english" />
</RadioGroup>
RadioButton
background extraction
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="false" android:drawable="@drawable/ic_spain" />
<item android:state_checked="true" android:drawable="@drawable/ic_spain_pressed" /> //pressed image is Large in size
<item android:drawable="@drawable/ic_spain" /> <!-- default -->
</selector>
I saved the selection in TinyDB
so that the application remembers my selection when I open my application. But whenever I open my application, the default selected background of the RadioButton appears Large. I took all images of the same size, drawable with the same padding.
The first flag is the default selected here. But it looks a little big in size
Now I have pressed the second flag. But the first flag does not come up to normal.
source to share
You have to change android:button="@null"
to android:button="@drawable/rb_germany"
and remove the background from each RadioButton. It will work fine.
Your updated RadioButton should look like this:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/rb_spain"
android:id="@+id/am_rb_spain" />
source to share