how to animate one item of layer-list

后端 未结 1 1383
情歌与酒
情歌与酒 2021-02-08 03:27

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 u

1条回答
  •  青春惊慌失措
    2021-02-08 03:52

    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 :

    
    
    
        
        
    
    
    

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

    
    

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

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

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

    0 讨论(0)
提交回复
热议问题