如何将animation-list设置为xml属性

Pie*_*rtz 5 android android-animation android-xml

有没有一种方法来设置并开始xml animation-list作为一个xml属性?我可以通过以下方式以编程方式设置和启动它:

    ImageView img = (ImageView) findViewById(R.id.loadingImageView);
    img.setBackgroundResource(R.drawable.loading_animation);
    AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
    frameAnimation.start();
Run Code Online (Sandbox Code Playgroud)

动画列表是:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
//...
android:oneshot="false" >

<item
    android:drawable="@drawable/loading_anim_frame_one"
    android:duration="50"/>
 <item
    android:drawable="@drawable/loading_anim_frame_two"
    android:duration="50"/>
Run Code Online (Sandbox Code Playgroud)

等等.

有没有办法xml只用标记来做这个,即没有java代码?

如果没有,是否有办法至少将其设置为xml属性,然后以编程方式启动它?

我不能使用单个drawable的旋转,因为动画按顺序包含几个drawable.

Mys*_*icϡ 16

你可以声明它

<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <scale
        android:duration="700"
        android:fillAfter="false"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.4"
        android:toYScale="1.4" />

    <scale
        android:duration="400"
        android:fillBefore="false"
        android:fromXScale="1.4"
        android:fromYScale="1.4"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="700"
        android:toXScale="0.8"
        android:toYScale="0.8" />

</set>
Run Code Online (Sandbox Code Playgroud)

只是一个参考.您必须更改动画类型和参数.根据我的知识,你将不得不使用java启动它.

编辑:

是对动画列表有用的链接


Fra*_*ola 5

我认为您应该首先加载动画:

Animation anim = AnimationUtils.loadAnimation(this, R.anim.animation_name);

img.startAnimation(anim);
Run Code Online (Sandbox Code Playgroud)