Android UI realizes ad banner rotation effect
One effect to be shared in this blog is to achieve the advertising banner rotation effect. This effect is also common. Some video applications often have it. Take 360 film and television Daquan as an example:
The effect with the red frame is what the Witch wants to share today. Let's think about what controls will be used first? What is the user experience?
Control, we may think of viewpager at once. That's right! Viewpager is used. What user experience will it have? It may have the following experiences:
1. The indicator changes as the picture is switched at intervals
2. Click the picture to jump to the specified page
How?
Layout start / bannerautoscrolldemo / RES / layout / banner.xml
A viewpager and the following five indicator points. Note that each point has the same style. We define the style in style.xml: / bannerautoscrolldemo / RES / values / styles.xml
Define dot graphic resources / bannerautoscrolldemo / RES / drawable / dot_ normal.xml
/BannerAutoScrollDemo/res/drawable/dot_ focused.xml
Define advertising entity / bannerautoscrolldemo / SRC / COM / Xiaowu / banner / demo / addomain.java
Implement switching logic
1. Timing switching
2. Switch pictures
3. Switch title
4. Switch indicator
Scheduled switching uses a class: scheduledexecutorservice
The function is to perform tasks regularly. The scheduled task we want to do here is to perform image switching once every 2 seconds
Define child threads
Notify viewpager to switch views through handle
We provide simulation data for testing
Viewpager logic processing
1. Fill in data (custom adapter)
2. Set page switching listening events
3. Set the viewpager click event in the instantiateitem method of the custom adapter
Here, our pictures are downloaded from the Internet. We use the universal-image-loader-1.8.6-with-sources.jar class library to load pictures asynchronously. See the code for details.
Finally, the complete code is given:
/BannerAutoScrollDemo/src/com/xiaowu/banner/demo/MainActivity.java
Source code download: http://xiazai.jb51.net/201612/yuanma/AndroidBannerAutoScroll (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.