Android realizes the sliding effect of Netease strict selection tab bar
The label bar is a very common control and seems to be a relatively simple control, but if you add an underline under the label, you can still play a lot of flowers.
Netease's strictly selected tab bar is very good, which hides many details:
After careful analysis, the following logic needs to be realized on the basis of simple tab bar:
I made a sample program, in which the difficulty is to calculate the position of the underline and the animation effect of the underline.
The above is the code for calculating the position of the underline. By passing in the position and positionoffset obtained in onpagescrolled(), the position of the underline under a label or between two labels is calculated. It should be noted that since the length of each label may be different, the length of the underline may also change during sliding, so it is necessary to calculate the left and right of the underline respectively.
This is the code to run the sliding animation of the underline when switching labels. It is implemented by valueanimator, and special treatment is made for the case that the underline exceeds the boundary to prevent the sliding speed from being too fast when the sliding distance is too large.
For more details, see https://github.com/wlkdb/page_ sliding
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.