Android custom control (implement view tree drawing indicator)

Previously, when writing the carousel bar or indicator, it was directly in the UI diagram. This effect is not good and gives the user a poor experience. Therefore, in his spare time, he wrote an indicator to show an elegant effect. When the finger slides, the small dots will slide bit by bit, and when the finger stops, the small red dots will also stop. First of all, let me talk about the principle I implemented

First, write a linear layout in the layout file to represent the dot, direction and position at the bottom, and then draw the dot in the shape. Then write the layout in the code. The specific steps are as follows:

1. Use layparams to add unselected small dots to the layout, such as gray;

2. Set a small red dot to indicate the state after sliding.

3. Get the distance between small circle points. Here, you can't simply getWidth and getHeight to get the distance between small circle points. Here, you need to use the view tree to observe the distance between the two points and the left screen, and then calculate the difference to get the distance.

4. Obtain the distance between the two when listening to the viewpager.

The code is as follows:

1、 Layout file

2、 Code

3、 Gets the distance between small red dots

4、 Let the little red dot linkage

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of 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
分享
二维码
< <上一篇
下一篇>>