ProgressBar:进度条,主要向用户展示当前任务的完成进度,例如游戏加载、app更新、文件下载等;
SeekBar:进度条的升级款,与ProgressBar不同的是用户可以自行拖动以控制进度;音量大小、音视频的播放进度等都可以用它实现;
RatingBar:星级评分条,这里我只用三个字描述:“打分的”,多用于电商类app以及各大应用商店,比如对某款app、某件商品评分
二、简单使用1、打开之前的布局文件activity_main.xml,先删掉之前定义的所有控件,然后再添加今天我们讲到的控件,如图1
图1
2、打开MainActivity.java,因为布局中之前定义的控件已经被删掉,所以代码中也需要清理,不然因为找不到控件id会报错;清掉后定义并绑定今天的控件
public class MainActivity extends AppCompatActivity {
private ProgressBar pbProgress;
private SeekBar sbProgress;
private RatingBar rbEvaluate;
@Override
protected void onCreate(Bundle savedInstancestate) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
pbProgress.setProgress(30);
sbProgress.setMax(100);
setListener();
}
private void setListener() {
sbProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.e("onProgressChanged======",progress "");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
rbEvaluate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Log.e("onRatingChanged======",rating "");
}
});
}
private void initView() {
rbEvaluate=findViewById(R.id.rb_evaluate);
pbProgress=findViewById(R.id.pb_progress);
sbProgress=findViewById(R.id.sb_progress);
}
}
代码中我用setProgress()方法为pbProgress设置了当前进度
三、官网对于上述控件的属性介绍1、RatingBar
android:isIndicator |
Whether this rating bar is an indicator (and non-changeable by the user). |
android:numStars |
The number of stars (or rating items) to show. |
android:rating |
The rating to set by default. |
android:stepSize |
The step size of the rating. |
2、SeekBar
android:thumb |
Draws the thumb on a seekbar. |
3、ProgressBar
android:animationResolution |
Timeout between frames of animation in milliseconds. |
android:indeterminate |
Allows to enable the indeterminate mode. |
android:indeterminateBehavior |
Defines how the indeterminate mode should behave when the progress reaches max. |
android:indeterminateDrawable |
Drawable used for the indeterminate mode. |
android:indeterminateDuration |
Duration of the indeterminate animation. |
android:indeterminateOnly |
Restricts to ONLY indeterminate mode (state-keeping progress mode will not work). |
android:indeterminateTint |
Tint to apply to the indeterminate progress indicator. |
android:indeterminateTintMode |
Blending mode used to apply the indeterminate progress indicator tint. |
android:interpolator |
Sets the acceleration curve for the indeterminate animation. |
android:max |
Defines the maximum value. |
android:maxHeight |
An optional argument to supply a maximum height for this view. |
android:maxWidth |
An optional argument to supply a maximum width for this view. |
android:min |
Defines the minimum value. |
android:minHeight | |
android:minWidth | |
android:mirrorForRtl |
Defines if the associated drawables need to be mirrored when in RTL mode. |
android:progress |
Defines the default progress value, between 0 and max. |
android:progressBackgroundTint |
Tint to apply to the progress indicator background. |
android:progressBackgroundTintMode |
Blending mode used to apply the progress indicator background tint. |
android:progressDrawable |
Drawable used for the progress mode. |
android:progressTint |
Tint to apply to the progress indicator. |
android:progressTintMode |
Blending mode used to apply the progress indicator tint. |
android:secondaryProgress |
Defines the secondary progress value, between 0 and max. |
android:secondaryProgressTint |
Tint to apply to the secondary progress indicator. |
android:secondaryProgressTintMode |
Blending mode used to apply the secondary progress indicator tint. |
四、补充
可以看到在代码中我用到了Log.e(),它是用于向控制台输出日志的,除了使用调试模式以外,合理使用日志输出也可以帮我们快速定位问题,除了e外,级别由低到高还有v, d, i, w;e的级别是最高的
图2
五、运行截图最后附上一张运行效果图
,