Android implements ImageView that can play GIF animation

Android native controls do not support playing GIF format pictures. As we all know, if you want to display a picture in Android, you can use ImageView to complete it, but if you set a GIF picture to ImageView, it will only display the first frame of the picture and will not produce any animation effect. Today, let's write a custom enhanced ImageView (inheriting ImageView), which can play GIF format pictures. Let's call it gifimageview for the time being.

1. Custom attributes

2. Get the attribute value from the custom view

3. Rewrite onmesure ()

4. Rewrite ondraw()

5. Add click event

It should also be noted that some mobile phones with systems above 4.0 will not play GIF animation after starting the hardware acceleration function, so we need to use Android manifest Disable the hardware acceleration function in XML by specifying Android: hardwareaccelerated = false.

--------------------------------------------------------------------------------

Now let's look at the effect after running. The layout file:

Auto in Figure 1_ If the play attribute is false, the first frame and a play button will be displayed. After clicking, the GIF image will run automatically. Auto in Figure 2_ If the play property is true, GIF will be played in a loop automatically. In Figure 3, the resources we give are static pictures. Because the custom view inherits ImageView, it has all the features of ImageView, so it can also display static pictures.

Source code download: http://xiazai.jb51.net/201609/yuanma/GifImageView (jb51.net). rar

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>