First, preface
ProgressBar itself represents the progress bar component, which also derives two commonly used components: Seekbar and Ratingbar, they use similar methods, but the display interface has a certain difference. Let's take a look at the instructions in the API documentation:
We can directly see ProgressBar inherit from the view class, direct subclasses have Absseekbar and contentloadingprogressbar, indirect subclasses have Ratingbar and Seekbar. Here are some ways to use these controls in turn.
Second, ProgressBar
ProgressBar is a component of the interface used to interact with users to improve user-friendliness and is typically used to show a user a time-consuming operation, to show the percentage of completion, without letting the user feel that the program is unresponsive. In the API documentation, we see that the XML attributes he supports are as follows:
XML attribute Name |
Description |
Android:animationresolution |
Animation time-out, must be an integer value, such as "100" |
Android:indeterminate |
This property is set to true to indicate that the progress is not accurately displayed |
Android:indeterminatebehavior |
Set how to describe the reach maximum when you choose not to accurately display progress |
Android:indeterminatedrawable |
Sets the Drawable object that is drawn when you choose not to display the progress accurately |
Android:indeterminateduration |
Set the duration for which the progress is not accurately displayed |
Android:indeterminateonly |
Setting only shows the progress mode with no precision (state hold mode will not work) |
Android:interpolator |
|
Android:max |
Set the maximum value that the progress can reach |
Android:maxheight |
Optional parameter sets the maximum height of the view |
Android:maxwidth |
Optional parameter sets the maximum width of the view |
Android:minheight |
Optional parameter sets the minimum height of the view |
Android:minwidth |
Optional parameter sets the minimum width of the view |
Android:mirrorforrtl |
Defines if it is necessary to reflect the relevant artboard in RTL mode, the default is False |
Android:progress |
Set progress values for which the progress has been completed |
Android:progressdrawable |
Sets the Drawable object corresponding to the progress bar track |
Android:secondaryprogress |
Second level progress bar, mainly used for cache usage scenarios |
The form is taken from the API19 document
The progress bar supports a variety of styles, which can be set directly by setting the Style property, and the following properties are given in the API:
Widget.ProgressBar.Horizontal 水平进度条
Widget.ProgressBar.Small 小环形进度条
Widget.ProgressBar.Large 大环进度条
Widget.ProgressBar.Inverse 普通大小的环形进度条
Widget.ProgressBar.Small.Inverse 小环形进度条
Widget.ProgressBar.Large.Inverse 大环形进度条
另外一种使用方式就是可以使用系统的ATT属性例如:
- Style= "? Android:attr/progressbarstyle"
- Style= "? Android:attr/progressbarstylehorizontal"
- Style= "? Android:attr/progressbarstyleinverse"
- Style= "? Android:attr/progressbarstylelarge"
- Style= "? Android:attr/progressbarstylelargeinverse"
- Style= "? Android:attr/progressbarstylesmall"
- Style= "? Android:attr/progressbarstylesmallinverse"
- Style= "? Android:attr/progressbarstylesmalltitle"
For example, the following code:
For the example on Crazy handout 3, I didn't actually do it, and the custom progress bar, while following the example in the book, showed that the two icons overlapped and did not show up on the progress, and the code was as follows:
And the display effect is:
The actual running effect is also the background of the simulation thread in the update UI is not performed according to the expected results, the beginning of the show is the bottom of the red picture, has not moved, and then all the update to this overlapping picture.
Find for a long time reason also don't know where out of the problem, this problem temporarily record, wait for time to solve. (Display problem with API22 simulator)
Online to find a progress bar example, feeling is not very complete, learning is not very systematic, think of Android comes with an example of the SDK, we find it, we first look at the effect:
The location of the example is under the &androidsdk&\samples\android-19\legacy\apidemos\src\com\example\android\apis\view folder and you can see
These 4 Java files are the corresponding 4 progress bar codes.
and the corresponding layout file can go down to the upper res folder. The code is no longer attached here. Myself to find the demo, I admit this, I learned a little depressed, marked.
Third, SeekBar
Seekbar is the slider bar, which is different from the progress bar when the general progress bar is filled with color progress, while the slider bar is used to represent progress values, and allows the user to drag the slider to change the value, such as the volume adjustment of Windows:
is a sliding bar. The style of the slider is specified by the android:thumb property.
Here is a simple small example, showing that the result is to display the value of the drag slider change on the TextView.
Simple effect:
Getting the dragged value requires setting his setonseekbarchangelistener to this listener, overriding his method. The example on the right-hand side is customizing his chute, which is given in the following block.
First, the style definition (progress_drawable.xml) of the chute is given:
The following is the style layout for the sample Main page:
If you want to mimic the slider for Windows to adjust the volume, just add a imageview to the front of the internal linear layout to make the same effect.
This is the background code, mainly the implementation of the listener.
These are just the basic usage of seekbar, of course, can also be implemented in a variety of ways, the following is the Internet to see the effect of netizens:
Example Links:
1. Custom Seekbar
2.Android dynamically displays progress when using Seekbar and moves with Seekbar
3. ProgressBar or Seekbar that can display floating text hints
Iv. Ratingbar
Star rating Bar, is actually a kind of drag bar, but the difference between the drag bar is that it provides stars to indicate progress. The common properties are as follows:
Property |
Description |
Android:isindicator |
Set whether the star rating allows the user to the table (true is not allowed to change) |
Android:numstars |
Set the star rating bar How many stars are there in total? |
Android:rating |
Set the star rating bar by default |
Android:stepsize |
Set the minimum number of stars to change each time |
Let's do a brief example to illustrate these properties:
Also look at the effect first:
Then we give the layout file:
Where Max and progress are the properties in the progress bar, because Ratingbar itself is a special progress bar, set the maximum value is 100, 5 stars display, indicating that a star is 20, step 0.5, indicating at least half a star can be selected at a time.
Background is mainly to deal with the change when the listener.
Five, PostScript
Recent chores, learning progress slowed down, encountered problems have been stuck for a long time, some problems need to learn more in-depth, look at the SDK examples and API documentation. The following sections skip the use of some simple controls and give the location of the sample code in the SDK. No more wasted space on blogs. Accelerate your learning schedule.
Android Development Self-study note (Android Studio) -4.5 ProgressBar and its subclasses