Android custom controls to achieve elegant advertising rotation map
preface
Today I bring you a new control C rotation chart. There are many blogs on the Internet to explain how to implement it. What are the characteristics of my? Or what are the differences?
It meets the basic requirements of the rotation chart, circularly slides, and can make a smooth transition when the last one is cut to the first one, which is simple and has strong expansibility
How to use
Let's show two kinds of renderings first
1 default effect
code implementation
In fact, the key code is just one line, which uses the entity class of bannerbean. There are three parameters, namely, the description text of the picture, the picture address, and the corresponding link after clicking
All the above are default values. Let's take a look at what can be customized
2. Custom effect
Figure 1 and Figure 2 are mainly different in the following points
1. I have only implemented two kinds of indicator and text position structure. You can also download the source code and expand 2. The color after the dot indicator is selected 3. The time interval of automatic playback 4. It supports the display of the default picture before the picture is loaded
Code implementation of custom effect
Next, we will demonstrate the implementation of Figure 2 through XML and Java code
1 xml
2 java
The effects of the above two codes are completely equivalent. In Java code, they are called by chain, making the code look more concise. It is very convenient to have wood, which greatly reduces the amount of code, and can be used directly. Well, let's take a look at the implementation code.
realization
Picasso is integrated into the picture download. For children's shoes unfamiliar with Picasso, you can see the basic usage of Picasso (II), a sharp tool for picture loading in my previous blog
The reference code of viewstub is not given here. You can visit my git to view it. The address will be given at the end of the article
This article is introduced here. Click here to view the source code
Here are the pictures for the test:
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.