Android custom ImageView realizes automatic zoom in and zoom out animation

This article is about how to generate a custom ImageView to automatically zoom in and out animation.

Why do you implement this function? Because I want to realize the image zooming in and out animation in viewpager, but the animation of several pages in viewpager will move together, and the enlarged full screen images will cover each other, which is very strange. So I searched the demo online and found nothing. Forced by helplessness... No more nonsense, just paste the code.

1. Add configuration file directly

When adding pictures directly to the layout file, you can use getdrawable () to obtain picture resources in the custom view code, and then draw pictures through drawbitmap. By constantly drawing the position of the picture, the function of zooming in and out can be achieved. The first case is directly added in the XML layout file:

2. How to load pictures through glide

If you load pictures through glide, you cannot directly use getdrawable to obtain picture resources. The way glide loads images also needs to be changed. No more nonsense, go straight to the code. Coolimageview loads images directly from glide's cache.

Coolimageview. Java: the only difference is the way to get pictures``` java

If you feel that the animation is not smooth enough, you can reduce the thread waiting time.

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