Learn two display items: ProgressBar is used for output and SeekBar is used for Input.
ProgressBar
1) Android XML file
......
<ProgressBarAndroid: id = "@ + id/c81_firstBar"
Style="? Android: attr/progressBarStyleHorizontal"
Android: layout_width = "200dp"
Android: layout_height = "wrap_content"
Android:Max= "200" <! -- The default value is 100 -->
Android: visibility = "gone"/>
<! -- Both gone and invisible are currently invisible-, but invisible retains the widget space in the layout, while gone does not -->
<ProgressBarAndroid: id = "@ + id/c81_secondBar"
Style ="? Android: attr/progressBarStyle"
.../>
<ProgressBarAndroid: id = "@ + id/c81_thirdBar"
Style ="? Android: attr/progressBarStyleLarge"
.../>
<ProgressBarAndroid: id = "@ + id/c81_forthBar"
Style ="? Android: attr/progressBarStyleSmall"
.../>
<Button Android: Id = "@ + ID/c81_mybutton"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "begin"/>
......
We noticed the style setting method. In the Android reference Progress, we found four styles in XML attributes. We set four progressbar for the experiment.
2) source code
ProgressBar is relatively easy. We need to know some basic operations about it. See the bold section below.
// In oncreate (), set layout and find firstbar, secondbar, thirdbar, fourthbar, And button by ID. skip this step.
// Firstbar.SetIndeterminate(True );
/* Invalid progressbar setting */
Button. setonclicklistener (New onclicklistener (){
Public void onclick (view v ){
If (precent = 0 ){
FirstBar.SetProgress(0 );
FirstBar.SetSecondaryProgress(0 );
SecondBar. setProgress (0 );
FirstBar.SetVisibility(View. VISIBLE);
SecondBar. setVisibility (View. VISIBLE );
ThirdBar. setVisibility (View. VISIBLE );
Forthbar. setvisibility (view. Visible );
Precent + = 10;
} Else if (precent <= firstbar.GetMax()){
// Of course, in this example, Max is 200, or 200 can be written directly, but getmax () is recommended ()
Firstbar.SetProgress(Precent );
// You can also use firstbar.IncrementProgressBy(10 );
Firstbar.SetSecondaryProgress(Precent + 10 );
// Secondbar. setprogress (precent );
/* The test proves that this does not work, including thirdBar and fourthBar */
Precent + = 10;
} Else {
FirstBar.SetVisibility(View. GONE);
SecondBar. setVisibility (View. GONE );
ThirdBar. setVisibility (View. GONE );
ForthBar. setVisibility (View. GONE );
Precent = 0;
}
}
});
As shown in, first check the first progressbar. style is set to the right of progressBarStyleHorizontal and is invalid, that is, firstBar.Setindeterminate(True ). If the setting is invalid, setProgress () does not work. You can set two progress bars: setProgress () and setSencondaryProgress (). The latter is lighter in color. Generally, we use a progress bar. The following three styles are progressBarStyle, progressBarStyleLarge, and progressBarStyleSmall. All three indicate that the execution process is in progress, but the displayed size and size are different. SetProgress () does not work for these three styles.
SeekBar
Progressbar uses and displays the progress, or notifies the user that the execution is in progress. This prevents the user from thinking that the program has a problem due to a long execution time and belongs to Output, while SeekBar belongs to Input, you can see where your fingers slide or click on the progress bar. We will add the following in the previous example.
1) Android XML file
<SeekBarAndroid: Id = "@ + ID/c81_seekbar"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>
<Textview Android: Id = "@ + ID/c81_info"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>
2) source code
Info = (TextView) findViewById (R. id. c81_info );
Seekbar = (SeekBar) findViewById (R. id. c81_seekbar );
// Seekbar uses setOnSeekBarChangeListener () to set the trigger method and process onProgressChanged ().
Seekbar.SetOnSeekBarChangeListener(New OnSeekBarChangeListener (){
Public voidOnProgressChanged(SeekBar arg0, int arg1, boolean arg2 ){
Int progess = arg0.GetProgress();
// GetProgress () obtains the current position
Info. setText ("Progress is" + progess + (arg2? "Trigger": "Nontrigger") + "by user .");
}
Public voidOnStartTrackingTouch(SeekBar arg0 ){
// Nothing to do
}
Public voidOnStopTrackingTouch(SeekBar arg0 ){
// Nothing to do
}
});
Related Links: My Andriod development articles