2

私は AnimationDrawable を作成しました。そのアニメーションを無限に繰り返し、ボタンのクリックでそのアニメーションを停止したいのですが、コードを共有しています

anim.xml ファイル

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="true" >
    <item android:drawable="@drawable/download_anim1" android:duration="100" />
    <item android:drawable="@drawable/download_anim2" android:duration="100" />
    <item android:drawable="@drawable/download_anim3" android:duration="100" />
    <item android:drawable="@drawable/download_anim4" android:duration="100" />
    <item android:drawable="@drawable/download_anim5" android:duration="100" />
</animation-list>

私のレイアウトファイルで

<ImageView
    android:id="@+id/imageViewAnimation"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:padding="3dp"
    android:layout_marginBottom="10dp"
    android:layout_weight="2"
    android:background="@color/colorOrange"
    android:src="@drawable/anim" />

そして、アニメーションを開始したアクティビティで

ImageView imageViewAnimationr = (ImageView) headerView.findViewById(R.id.imageViewHeaderDownloadAnimation);
AnimationDrawable animationDrawable = (AnimationDrawable) imageViewAnimationr.getDrawable();
animationDrawable.start();
4

2 に答える 2

2

アニメーションを繰り返すためのsetOneShotを見つけ、任意のインスタンスでアニメーションを停止するためのStopを見つけました。

于 2015-12-15T05:53:54.973 に答える