android:如何停止动画放大中的重复
下面是我的zoom_in.xmlandroid:如何停止动画放大中的重复,android,android-layout,android-animation,Android,Android Layout,Android Animation,下面是我的zoom_in.xml <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" > <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXSc
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="0"
android:fromYScale="0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" >
</scale>
</set>
现在我称之为
zoomIn = loadAnimation(getContext(),
R.anim.zoom_in);
view.startAnimation(zoomIn);
不要使用“设置”或“对象动画制作程序”:
将重复计数设置为0
zoomIn = loadAnimation(getContext(), R.anim.zoom_in);
zoomIn.setRepeatCount(0);
将AnimationListener
添加到zoomIn
中,如下所示
zoomIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// clear animation here
view.clearAnimation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
希望这会有所帮助。如果你没有提到android:repeatCount='“1”怎么办?请尝试在代码中添加
AnimationListener
,并在onAnimationEnd
方法中停止动画。如果我没有提到repeat count,它会放大3倍。如果我重复计算,它也会重复3次。给我看你的java代码,并尝试第二个选项。@ELITE请检查我的代码一次,有错误吗?
zoomIn = loadAnimation(getContext(), R.anim.zoom_in);
zoomIn.setRepeatCount(0);
zoomIn.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// clear animation here
view.clearAnimation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});