Detailed explanation of GIF image examples displayed on Android

Detailed explanation of GIF image examples displayed on Android

Gif animation is still commonly used in Android. For example, there are many GIF images in Sina Weibo, and the display is very good, so I also want to get one. After many searches and sorting, I finally got it. In fact, there are many open-source GIF display codes on GitHub. I have downloaded several, but they are not very ideal, which is not what I completely want. So sometimes you have to learn to summarize and sort out the open source things into your own. Now it's boring and just needs friends, so now you sort them out and keep them for future use!

Without much nonsense, go straight to the figure above:

The class android.graphics.movie in Android is mainly used here, which is a very convenient tool provided by Android. First, rewrite the control view and customize a gifview showing GIF diagram. The code is as follows:

Movie actually manages multiple frames in GIF animation. You only need to use settime() to make it draw the corresponding frame image during draw(). Through the conversion relationship between the current time and duration, it is easy to realize the effect of GIF moving.

Secondly, define the view in the XML layout file. The code is as follows:

Finally, the code used in mainactivity is as follows:

Note: the only difference from ImageView and other views is that I added a GIF attribute.

This code is very good and easy to use. In fact, you can use it well if you don't understand what the code means. You only need to understand the lines of comments I write and the lines of code in the activity!

Thank you for reading, hope to help you, thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>