Function implementation of drag bar and star evaluation bar of Android advanced interface component

One drag bar

Android phone volume settings are given a drag bar, so that users can drag the slider to set. Here we introduce the drag bar.

Android drag bar control inherits from ProgressBar control, so it can support XML attribute of ProgressBar. But he has his own unique attributes:

Android: Max sets the maximum drag of two

Android: progress setting initialization progress

Android: thumb setting slider graphics

In terms of event monitoring, you should pay attention to the drag bar: we are not monitoring the user's click operation, but monitoring the change of the slider. Let's use an example to simply operate the drag bar.

Example: a drag bar and text are given on the interface, and the text is dynamically displayed by sliding the slider

1. Create a new project and add a text and drag bar in the layout file. Here I set the current progress value and slider graph

2. Get the text and drag bar from the code and add a listener to the drag bar. The listener controls the dynamic display of text. There are three methods for listening. Note: rewrite the methods for starting and ending sliding. The other one is related to whether it is user sliding. We don't care about it

Run the code and slide the slider to see the dynamic display content of the text.

II. Star bar

Many video software and application market software have the function of star rating. This is the scoring application scenario: drag the star rating bar, and then click a submit button to complete the scoring. Here, let's take a brief look at the properties of the star evaluation bar, and then simulate a similar star evaluation function.

Android: isindicator indicates whether it is an indicator, that is, whether it can be rated by the user. The value of "true" cannot be changed

Android: numstars total number of stars

Android: rating default star of star bar

Android: stepsize: the component of a change in star rating is 0.5 by default. The user drags to change the star rating by 0.5 at a time

Example: make a simple scoring interface

1. For a new project, display text, star bar and submit button are added to the layout

2. Instantiate and display text, star bar and button in the main activity

3. Add a listening event to the button to obtain the score of the star bar and display it in the text. The star rating is obtained through the getrating () method

Run the code, and the effect is as follows:

The above is the function realization of the drag bar and star rating bar of Android advanced interface components introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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