如何动画层列表一个项目 [英] how to animate one item of layer-list

查看:113
本文介绍了如何动画层列表一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图层列表对象,它包含两个图像,一个是背景, 另一种是,将在被raotated旋转磁盘映像 背景图像的顶部。比如我用这层列表作为的LinearLayout的背景下, 我只想动画层列表disk_bg项目;

I have a layer list object, it contain two images, one is background, and the other is a rotation disk image which will be raotated at the top of the background image. i.e. I use this layer-list as a linearlayout background, and I only want to animate "disk_bg" item of the layer-list;

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

I use this layer-list as a layout background, do you know how can I animate the disk_bg layer in my application?

你能帮助我,非常感谢你〜

can you help me, many thanks to you~

你不去找我的问题?或者有没有办法做到这一点?

don't you get my question? or there is no way to do that?

推荐答案

首先创建2个(或以上)层列表资源即* layer_frame1.xml *和* layer_frame2.xml *,你设置你的帧。在你的情况让我们说改变了android:顶盘项目

First create 2(or more) layer-list resources ie *layer_frame1.xml* and *layer_frame2.xml* , where you set your frames. In your case let's say changing the android:top of the disk item.

然后创建你设置帧的时间及次序动画列表资源:

Then create an animation-list resource where you set the timing and order of the frames :

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

将其保存在一个文件,即*绘制/ player_animation.xml *并将其设置为背景的一个视图

Save it in a file ie *drawable/player_animation.xml* and set it as background on a View

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

最后,在你的code只是说,当你想要的动画开始。

Finally in your code just say when you want the animation start.

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

当心不要启动动画里面的的onCreate()的方法。

Watch out do not start the animation inside onCreate() method.

这篇关于如何动画层列表一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆