Android custom semicircular disc scroll selector

Some time ago, the company's project required a special sliding selector, and the effect is as follows:

Functional requirements: the semicircular turntables on both sides can be rotated, and the icons on the turntable also scroll together. The small icon pointed by the blue and red icon becomes highlighted and selected.

When I first saw this requirement, I thought that it must be done with custom controls, so this idea came into being:

The semicircular rolling turntable custom view inherits the ViewGroup, rewrites the sliding event, and customizes the placement angle of the pictures on the disc. As for the selected state pointed by the blue and red arrow icons, you can draw an area with the coordinate array to judge whether there are qualified icons scrolling to this position. If so, set the transparency of the control where the icon is located to 1, If you don't get to this position, set it to the unselected state of 0.5 transparency. The idea is settled. It is expected to work, so you start to actually try to write code to realize this custom control and function.

Next, I will attach the core code directly with clear comments:

Attrs.xml file code:

Class code of custom control:

Then you can get the selected object according to the callback method in the activity. / / the methods on the left and right sides are the same, and the methods on the left are listed here:

Finally, paste the layout file:

//Here is the picture list displayed on the semicircular turntable selector. I use XML to transfer it statically or dynamically

Then create an arrays. XML file under values

That's it.

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