Android wheel selection time control details

Wheel selection control

Android's built-in selection time control is a little ugly. It is often disliked by products and design. I hope to make it into a wheel selection like IOS. The following is my customized selection control based on numberpicker. The effects are as follows:

principle

There are wheelviews with more marks on GitHub to achieve the roller effect, but after reading the source code, it is found that the data is filled in at one time. If you choose the time, filling in 10 years is 10 * 365 = 3650 data, that is, more than 3000 textviews are new. It is terrible to think about it, but it must not be possible. So you think of using numberpicker to dynamically fill in data and set only 5 data at a time, When the change is selected, the data filling is reset, so the key is the calculation of the filled data.

Set logical code of data part:

Monitor the roller and reset the filling data:

Select values and strings

Similarly, numberpicker is used for encapsulation and dynamic filling of values to achieve the effect of rolling transformation.

The complete code is as follows:

About numberpicker

The default numberpicker often follows the system and cannot change the font color and split line color. Considering that it may be ugly or have other needs, the custom numberpicker changes some of its properties by reflection. The code is as follows:

The complete demo can be viewed and downloaded from GitHub at: https://github.com/lizebinbin/PickTimeView.git thank you!

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.

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
分享
二维码
< <上一篇
下一篇>>