Set Animated .GIF As Background Android

前端 未结 3 799
借酒劲吻你
借酒劲吻你 2020-12-01 05:04

I am new to Android and I am having trouble playing an animated .gif file in the background of my layout. When I run the application the background is a single frame of the

3条回答
  •  天命终不由人
    2020-12-01 05:11

    As Martin says, Android does not support GIFs. As a workaround, Android offers Animation List/AnimationDrawable. You will need to convert the GIF into individual frames [.png files]. I use GIMP for the conversion

    Original GIF image

    This GIF can be broken down into its frames:

    GIF frames in GIMP

    Save them as frame01.png, frame02.png, and so on, and create an animation-list XML file, say, progress_animation.xml

    
    
    
    
    ....
    
    

    To begin the animation, you need to cast the image to an AnimationDrawable, and call start() on it

    AnimationDrawable progressAnimation = (AnimationDrawable) yourImageView.getBackground();
    progressAnimation.start();
    

提交回复
热议问题