【问题标题】:how to animate one item of layer-list如何为图层列表中的一项设置动画
【发布时间】:2018-10-18 20:32:48
【问题描述】:

我有一个图层列表对象,它包含两个图像,一个是背景, 另一个是旋转磁盘图像,将在 背景图像的顶部。即我使用这个图层列表作为线性布局背景, 我只想为图层列表的“disk_bg”项设置动画;

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/
android">
       <item android:drawable="@drawable/player_bg" />

       <item  android:top="166dp" >
             <bitmap  android:id="@+id/disk_bg" android:src="@drawable/cd"
       android:gravity="center" />
       </item>

我使用这个图层列表作为布局背景,你知道如何在我的应用程序中为 disk_bg 图层设置动画吗?

你能帮帮我吗,非常感谢你~

你不明白我的问题吗?还是没有办法做到这一点?

【问题讨论】:

    标签: android animation android-animation


    【解决方案1】:

    首先创建 2(或更多)层列表资源,即 *layer_frame1.xml* 和 *layer_frame2.xml* ,您可以在其中设置框架。在您的情况下,假设更改磁盘项目的 android:top。

    然后创建一个动画列表资源,您可以在其中设置帧的时间和顺序:

    <?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/layer_frame1"
            android:duration="100"/>
        <item
            android:drawable="@drawable/layer_frame2"
            android:duration="100"/>
    
    </animation-list>
    

    将其保存在文件中,即 *drawable/player_animation.xml* 并将其设置为视图上的背景

    <View
            android:id="@+id/animation_test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/player_animation" />
    

    最后在你的代码中说明你希望动画何时开始。

     ((AnimationDrawable)findViewById(R.id.animation_test).getBackground()).start();
    

    注意不要onCreate() 方法中启动动画。

    【讨论】:

    猜你喜欢
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多