【发布时间】:2021-07-13 15:48:41
【问题描述】:
如何创建一个正确的旋转按钮动画,我尝试了下面的代码,但它一直在崩溃。
button_spin_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite" />
用法
@Override
public void onStart() {
super.onStart();
account_login.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(getApplicationContext(), R.drawable.button_spin_animation), null);
Drawable[] sb = account_login.getCompoundDrawables();
AnimationDrawable animDrawable = (AnimationDrawable) sb[0];
animDrawable.start();
}
错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.android.buyer/com.app.android.buyer.Login}: android.content.res.Resources$NotFoundException: Drawable
Caused by: android.content.res.Resources$NotFoundException: Drawable com.app.android.buyer:drawable/button_spin_animation with resource ID #0x7f080146
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/button_spin_animation.xml from drawable resource ID #0x7f080146
at
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8: <rotate> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.RotateDrawable.verifyRequiredAttributes(RotateDrawable.java:106)
at android.graphics.drawable.RotateDrawable.inflate(RotateDrawable.java:76)
at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:145)
at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
at
【问题讨论】:
标签: android android-animation drawable