我有一个广播组包含两个单选按钮:
<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>
现在我想将动画添加到单选按钮。我为每个单选按钮状态设置了两个动画 例如 : 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就像animation_radio_on只是改变图片。 我的选择器:
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>
但是发生了一些错误,我的应用无法运行。 我花了很多时间来搜索关于单选按钮的动画。我也请参考此链接:Android Radio Button Animation。
但我认为这不适合我的情况。 你对我的问题有任何想法吗?谢谢。 编辑:我的日志猫:
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)
答案 0 :(得分:0)
我会要求一个logcat,但是从我的头脑中,你在布局中将按钮本身设置为null,然后你(可能)指示资源管理器为其分配你的动画,所以也许你的问题在那里。
我没有看到您将动画分配到单选按钮的位置(您可能在代码中执行此操作)。
Logcat和代码将有助于更多地了解这一点。