Android thread realizes picture rotation
1、 Realization effect
This article implements a simple picture rotation, initializing 3 resource pictures, changing the picture background once every 3 seconds, and playing in rotation.
2、 Knowledge points
Thread thread start(), sleep(); Handler mechanism; Android control ImageView, setbackgroundresource (ID);
It is relatively simple, and the basic knowledge involved is basic knowledge.
3、 Basic ideas
1. Initialize resource file
2. Create an instantiated thread object new thread()
3. Handler mechanism, SendMessage (MSG); To process thread information to change the currently displayed resource picture to the next one
4. The thread sets the sleep time to set the time interval of picture rotation,
5. Send information every other period of time through the handler mechanism to realize the transformation of picture resources and realize the rotation
-->>Code implementation:
(1) Layout: just an ImageView control
K1.jpg, k2.jpg, K3, JPG are three pictures
(2) The Java code implements the rotation transformation of the background picture:
(3) So far, the picture rotation effect has been realized, but the appreciation is not high. You can appropriately add some animation to make the picture conversion more dynamic and dynamic, and you can see the transformation process, rather than a simple static transformation.
4、 Extension -- Animation
Plus zoom animation, so that the picture rotation can see the replacement process, dynamic rotation function
In this way, the effect will be better. You can also add displacement animation to make the picture come in from the right, or come in from the left and go out from the right when changing the picture.
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.