Android ratingbar: evaluation bar control

Ratingbar is an extension of seekbar and ProgressBar. It is an indirect subclass of ProgressBar. You can use ProgressBar related properties. There are three styles of ratingbar: the default style (ratingbar style), the small style (ratingbar style small) and the large style (ratingbar style indicator). Among them, the ratingbar in the default style is commonly used and can interact, while the other two cannot interact. Explain the usage of ratingbar component with a simple example. Add a button named "ratingbardemo" in the layout file main.xml of the project widgetdemo to start ratingbaractivity. Add the following code in main.xml:

Click button and start ratingbaractivity. The code is as follows:

At the same time, declare the activity in the androidmanifest.xml file:

<activity android:name=".ratingBarActivity"></activity>

The running effect of ratingbaractivity is shown in Figure 1.

The contents of the layout file ratingbar.xml used by ratingbaractivity are as follows:

The layout file uses the LinearLayout layout, in which a textview and a ratingbar are placed, and the related properties of the ratingbar are set. Here are the functions of each attribute:

The code of ratingbaractivity.java is as follows:

Ratingbaractivity sets the onratingbarchangelistener listener for the ratingbar object. When the user clicks ratingbar to cause a change in the number of selected stars, the interface will monitor the event and call the onratingchanged() method to update the content displayed in textview. The three parameters of onratingchanged() have the following meanings.

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