Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将动画列表设置为xml属性_Android_Android Animation_Android Xml - Fatal编程技术网

Android 如何将动画列表设置为xml属性

Android 如何将动画列表设置为xml属性,android,android-animation,android-xml,Android,Android Animation,Android Xml,是否有方法将xml动画列表作为xml属性设置和启动?我可以按如下方式以编程方式设置和启动它: ImageView img = (ImageView) findViewById(R.id.loadingImageView); img.setBackgroundResource(R.drawable.loading_animation); AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackgro

是否有方法将
xml
动画列表作为
xml
属性设置和启动?我可以按如下方式以编程方式设置和启动它:

    ImageView img = (ImageView) findViewById(R.id.loadingImageView);
    img.setBackgroundResource(R.drawable.loading_animation);
    AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
    frameAnimation.start();
动画列表为:

<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"/>

等等

是否有一种方法可以只使用
xml
标记,即不使用java代码

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


我不能使用单个可绘制对象的旋转,因为动画由多个可绘制对象按顺序组成。

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

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

img.startAnimation(anim);
你可以把它声明为

<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>

只是一个参考。您必须更改动画类型和参数。据我所知,您必须使用java启动它

编辑:


是有助于动画列表添加alpha和translation示例以供将来参考的链接:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="400"
        android:fromYDelta="-100%p"
        android:toYDelta="0%p" />

    <alpha
        android:duration="800"
        android:fromAlpha="0"
        android:toAlpha="1" />
</set>


谢谢您的回答。我用java加载和启动它的代码运行良好。我正在寻找一种重构它的方法,这样至少可以将动画列表设置为xml布局中的图像视图。所以,我对xml部分很好奇。谢谢。我必须使用一个动画列表,因为动画是由多个可绘制对象按顺序组成的,而不是单个可绘制对象的动画。考虑到这一点,我不确定我怎么能利用你的建议。如蒙指教,不胜感激。切克。这可能会有帮助。这个链接非常有用。如果你把它编辑成你的答案,我会接受的。请帮我解决我的问题…我被困得很厉害。。。