android 中文本视图左侧可绘制对象中的闪烁动画
Blink Animation in left drawable of textview in android
我想设置blink动画,在textview的compound drawable(left)中。
我关注了link:
http://chiuki.github.io/advanced-android-textview/#/4
它对我很有帮助,而且工作起来很有魅力。
但是,我没有实现blink动画,请指导我正确的方法。
我用来做blink动画的xml文件如下:
blink_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
并在文本视图中指向此 xml,如下所示:
android:drawableLeft="@drawable/blink_anim"
但它抛出异常,logcat 视图:
02-27 07:24:34.533: E/AndroidRuntime(1128): FATAL EXCEPTION: main
02-27 07:24:34.533: E/AndroidRuntime(1128): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.animation.app/com.animation.app.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.access0(ActivityThread.java:141)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.os.Looper.loop(Looper.java:137)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Method.invoke(Method.java:525)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-27 07:24:34.533: E/AndroidRuntime(1128): at dalvik.system.NativeStart.main(Native Method)
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.Activity.setContentView(Activity.java:1895)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.animation.app.MainActivity.onCreate(MainActivity.java:18)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.Activity.performCreate(Activity.java:5133)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 11 more
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: java.lang.reflect.InvocationTargetException
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Constructor.constructNative(Native Method)
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 27 more
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/blink_animation.xml from drawable resource ID #0x7f020059
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.content.res.Resources.loadDrawable(Resources.java:2091)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.widget.TextView.<init>(TextView.java:802)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.widget.TextView.<init>(TextView.java:614)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 30 more
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag set
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:897)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.content.res.Resources.loadDrawable(Resources.java:2087)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 33 more
Binary XML file line #2: invalid drawable tag set
告诉你在 drawable 中不能有 <alpha
标签。
您引用的link有
<animation-list>
<item android:drawable="@drawable/ic_wifi_0"
android:duration="250" />
<item android:drawable="@drawable/ic_wifi_1"
android:duration="250" />
<item android:drawable="@drawable/ic_wifi_2"
android:duration="250" />
<item android:drawable="@drawable/ic_wifi_3"
android:duration="250" />
</animation-list>
这是不同类型的动画,因此您需要自己创建这些可绘制对象并在 animation-list
中列出它们
我想设置blink动画,在textview的compound drawable(left)中。
我关注了link: http://chiuki.github.io/advanced-android-textview/#/4
它对我很有帮助,而且工作起来很有魅力。 但是,我没有实现blink动画,请指导我正确的方法。
我用来做blink动画的xml文件如下:
blink_anim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
并在文本视图中指向此 xml,如下所示:
android:drawableLeft="@drawable/blink_anim"
但它抛出异常,logcat 视图:
02-27 07:24:34.533: E/AndroidRuntime(1128): FATAL EXCEPTION: main
02-27 07:24:34.533: E/AndroidRuntime(1128): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.animation.app/com.animation.app.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.access0(ActivityThread.java:141)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.os.Looper.loop(Looper.java:137)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Method.invoke(Method.java:525)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-27 07:24:34.533: E/AndroidRuntime(1128): at dalvik.system.NativeStart.main(Native Method)
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.Activity.setContentView(Activity.java:1895)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
02-27 07:24:34.533: E/AndroidRuntime(1128): at com.animation.app.MainActivity.onCreate(MainActivity.java:18)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.Activity.performCreate(Activity.java:5133)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 11 more
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: java.lang.reflect.InvocationTargetException
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Constructor.constructNative(Native Method)
02-27 07:24:34.533: E/AndroidRuntime(1128): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 27 more
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/blink_animation.xml from drawable resource ID #0x7f020059
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.content.res.Resources.loadDrawable(Resources.java:2091)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.widget.TextView.<init>(TextView.java:802)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.widget.TextView.<init>(TextView.java:614)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 30 more
02-27 07:24:34.533: E/AndroidRuntime(1128): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag set
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:897)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
02-27 07:24:34.533: E/AndroidRuntime(1128): at android.content.res.Resources.loadDrawable(Resources.java:2087)
02-27 07:24:34.533: E/AndroidRuntime(1128): ... 33 more
Binary XML file line #2: invalid drawable tag set
告诉你在 drawable 中不能有 <alpha
标签。
您引用的link有
<animation-list>
<item android:drawable="@drawable/ic_wifi_0"
android:duration="250" />
<item android:drawable="@drawable/ic_wifi_1"
android:duration="250" />
<item android:drawable="@drawable/ic_wifi_2"
android:duration="250" />
<item android:drawable="@drawable/ic_wifi_3"
android:duration="250" />
</animation-list>
这是不同类型的动画,因此您需要自己创建这些可绘制对象并在 animation-list