首页 > 解决方案 > 使用向左/向右拖动可绘制动画倒带

问题描述

我有动画可绘制

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
        android:oneshot="true">
    <item            android:duration="70"            android:drawable="@mipmap/scene00089"/>
    <item            android:duration="70"            android:drawable="@mipmap/scene00088"/>
    <item            android:duration="70"            android:drawable="@mipmap/scene00087"/>
    <item            android:duration="70"            android:drawable="@mipmap/scene00086"/>
    //......

只有当我向右(通常运行)或向左(反向)拖动时才应该播放。我已经实现了如何使用另一个具有反向动画的文件来反向播放它,但我需要解决的唯一问题是如何仅在拖放时拖动并停止播放它。

标签: javaandroidanimationkotlindrag

解决方案


您需要一个视图来播放动画,因此最好在布局视图层次结构中创建一个视图并在其上应用动画,如下所示。希望这会帮助你。

image.setBackgroundResource(R.anim.cubicfacetween);
AnimationDrawable animationDrawable = (AnimationDrawable) image.getBackground();
animationDrawable.start();

推荐阅读