【问题标题】:Repeat AnimationDrawable for infinite number and stop it on button click无限重复 AnimationDrawable 并在按钮单击时停止
【发布时间】:2015-12-15 05:35:45
【问题描述】:

我创建了一个 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();

【问题讨论】:

    标签: android android-animation animationdrawable


    【解决方案1】:

    我只是找到setOneShot 来重复动画并找到Stop 来在任何情况下停止动画。

    【讨论】:

      【解决方案2】:

      您可以更改oneshot=false 以无限次重复,并在您可以使用animationDrawable.stop() 的任何条件下停止 喜欢它:-

      <?xml version="1.0" encoding="utf-8"?>
      <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
          android:oneshot="false">
          <item android:drawable="@drawable/img_one" android:duration="200" />
          <item android:drawable="@drawable/img_two" android:duration="200" />
          <item android:drawable="@drawable/img_three" android:duration="200" />
      </animation-list>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-11
        • 2015-04-25
        • 1970-01-01
        • 2022-11-28
        • 2012-10-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多