Home » Android » android – how to animate one item of layer-list

android – how to animate one item of layer-list

Posted by: admin May 14, 2020 Leave a comment


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/
       <item android:drawable="@drawable/player_bg" />

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

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?

How to&Answers:

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



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

        android:background="@drawable/player_animation" />

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


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