【发布时间】:2011-09-27 04:55:44
【问题描述】:
我对 android 中的动画(以及几乎其他任何东西)真的很陌生。有没有办法为 ImageButton 设置动画?我只是想有时旋转按钮。就这样。有什么帮助吗?
谢谢。
【问题讨论】:
标签: android animation imagebutton
我对 android 中的动画(以及几乎其他任何东西)真的很陌生。有没有办法为 ImageButton 设置动画?我只是想有时旋转按钮。就这样。有什么帮助吗?
谢谢。
【问题讨论】:
标签: android animation imagebutton
试试这个代码 sn-p。
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:duration="1000" />
</set>
在java文件中
ImageButton imgbt = (ImageButton)findViewById(R.id.your_id);
Animation ranim = (Animation)AnimationUtils.loadAnimation(context, R.anim.rotate);
imgbt.setAnimation(ranim);
【讨论】:
java.lang.ClassCastException: android.view.animation.AnimationSet 错误:` RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.rotate);`
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360" />
Java 代码:
RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(context,R.anim.rotate);
view.startAnimation(rotateAnimation);
【讨论】: