Android custom star slidable scoring control

This example shares the specific method of Android custom star sliding scoring control for your reference. The specific contents are as follows

This control is implemented by linear layout combined with ImageView.

It has the function of displaying scores and sliding scores. You can set 0-10 scores, set the star picture by yourself, whether you can click and slide, and the star spacing.

The effects are as follows:

The following three pictures need to be prepared

First look at the custom attributes:

Layout file

The first control star: ratable is set to false and only has the display function. The second is true, which allows sliding scoring and displays the score on textview.

The following is the control code

The basic implementation principle is to calculate the score through the coordinates, then set each ImageView to display three different star pictures according to the score, judge whether to process the touch event according to the ratable variable, and determine the index through the position of the touch position in the coordinate array point [], which is the score. And notify the change of score through onratechangelister.

The last is the activity code

GitHub address starratingview

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