简体   繁体   中英

Android java stop a animation after completed

How can i stop a animation after it has completed?

My animation is the image fades in

code:

Java:

        super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageView imageView= (ImageView)findViewById(R.id.tCat);
    Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.anim);
    imageView.startAnimation(fadeInAnimation );

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="5000"
    android:repeatCount="infinite"/>
    </set>

尝试删除android:repeatCount =“infinite”,因为你不想重复它。

如果是非重复动画,它将在完成时结束,否则您可以将重复计数器设置为0以使其在当前执行后结束。

fadeInAnimation.setRepeatCount( 0 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM