I have one radio group contains two radio button :
<RadioGroup
android:id="@+id/radios"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:inputType="text"
android:orientation="vertical" >
<RadioButton
android:id="@+id/first"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:button="@null"
android:drawablePadding="30dp"
android:drawableRight="@drawable/selector_radio"
android:text="2 times"
android:textSize="20sp"
android:layout_marginLeft="20dp" />
<RadioButton
android:id="@+id/second"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:button="@null"
android:drawablePadding="30dp"
android:drawableRight="@drawable/selector_radio"
android:text="3 times"
android:textSize="20sp"
android:layout_marginLeft="20dp" />
</RadioGroup>
And now I want to add animation to radio button. I have two animation for each state of radio button For example : animation_radio_off :
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/btn_off_00"
android:duration="10"/>
<item
android:drawable="@drawable/btn_off_00"
android:duration="10"/>
......
</animation-list>
animation_radio_off is like animation_radio_on just change picture. My selector:
selector_radio.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/animation_radio_on"
android:state_checked="true" />
<item
android:drawable="@drawable/animation_radio_off"
android:state_checked="false"/>
</selector>
But something error happend and my app can not run. I spend many time to search about animation for radio button. I also refer this link : Android Radio Button Animation.
But i gusse it not fit my case. Do you have any idea for my problem ? Thanks you. Edit: my log cat:
12-02 17:40:18.155: E/AndroidRuntime(25421): FATAL EXCEPTION: main
12-02 17:40:18.155: E/AndroidRuntime(25421): Process: com.example.knock, PID: 25421
12-02 17:40:18.155: E/AndroidRuntime(25421): android.view.InflateException: Binary XML file line #14: Error inflating class android.widget.RadioButton
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.createView(LayoutInflater.java:640)
12-02 17:40:18.155: E/AndroidRuntime(25421): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
12-02 17:40:18.155: E/AndroidRuntime(25421): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:428)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.app.Dialog.setContentView(Dialog.java:580)
12-02 17:40:18.155: E/AndroidRuntime(25421): at com.example.knock.SettingActivity.onClick(SettingActivity.java:81)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.View.performClick(View.java:5162)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.View$PerformClick.run(View.java:20873)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.os.Handler.handleCallback(Handler.java:739)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.os.Handler.dispatchMessage(Handler.java:95)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.os.Looper.loop(Looper.java:145)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.app.ActivityThread.main(ActivityThread.java:5834)
12-02 17:40:18.155: E/AndroidRuntime(25421): at java.lang.reflect.Method.invoke(Native Method)
12-02 17:40:18.155: E/AndroidRuntime(25421): at java.lang.reflect.Method.invoke(Method.java:372)
12-02 17:40:18.155: E/AndroidRuntime(25421): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
12-02 17:40:18.155: E/AndroidRuntime(25421): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
12-02 17:40:18.155: E/AndroidRuntime(25421): Caused by: java.lang.reflect.InvocationTargetException
12-02 17:40:18.155: E/AndroidRuntime(25421): at java.lang.reflect.Constructor.newInstance(Native Method)
12-02 17:40:18.155: E/AndroidRuntime(25421): at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.view.LayoutInflater.createView(LayoutInflater.java:614)
12-02 17:40:18.155: E/AndroidRuntime(25421): ... 21 more
12-02 17:40:18.155: E/AndroidRuntime(25421): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/selector_radio.xml from drawable resource ID #0x7f020069
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.content.res.Resources.loadDrawableForCookie(Resources.java:3707)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.content.res.Resources.loadDrawable(Resources.java:3575)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.content.res.TypedArray.getDrawable(TypedArray.java:750)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.widget.TextView.<init>(TextView.java:1142)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.widget.Button.<init>(Button.java:115)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.widget.CompoundButton.<init>(CompoundButton.java:84)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.widget.RadioButton.<init>(RadioButton.java:65)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.widget.RadioButton.<init>(RadioButton.java:61)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.widget.RadioButton.<init>(RadioButton.java:57)
12-02 17:40:18.155: E/AndroidRuntime(25421): ... 24 more
12-02 17:40:18.155: E/AndroidRuntime(25421): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'duration' attribute
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:308)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1063)
12-02 17:40:18.155: E/AndroidRuntime(25421): at android.content.res.Resources.loadDrawableForCookie(Resources.java:3691)
I would ask for a logcat, but from the top of my head, you are setting the button itself to null in the layout, and then you (probably) instruct the resource manager to assign to it your animations, so maybe your problem is there.
I don't see where you assign the animation to the radio button (you probably do it in code).
Logcat and code would be helpful in shedding more light on this.