基本界面控件-5进度条
来源:互联网 发布:大华监控域名 编辑:程序博客网 时间:2024/05/02 10:31
五、基本界面控件-5进度条
5.5 进度条
5.5.1 ProgressBar
图5.5.1 ProgressBar
android.widget. ProgressBar,继承自android.view.View 。在android.widget包中。对应对话框ProgressDialog。
ProgressBar有两种展示方式,表盘形式(普通、小、大)和条形填充形式。在layout定义时,需要通过设施style属性类设置展示方式。
常用属性设置:
style
显示方式,取值:
?android:attr/progressBarStyleLarge / progressBarStyle / progressBarStyleSmall / progressBarStyleHorizontal
android:max
progressBarStyleHorizontal方式时,进度条满时的值。
android:progress
progressBarStyleHorizontal方式时,进度条主进度当前值。
android:secondaryProgress
progressBarStyleHorizontal方式时,进度条次进度当前值。
- <ProgressBar android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleLarge" />
- <ProgressBar android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyle"/>
- <ProgressBar android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleSmall" />
- <ProgressBar android:id="@+id/myProgressBar"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- style="?android:attr/progressBarStyleHorizontal"
- android:max="100"
- android:progress="50"
- android:secondaryProgress="75"/>
progressBarStyleHorizontal方式时,就需要指定进度条最大值,当前值,次要的当前值。还可以在代码中手动设置。
通过按钮改变progress和secondaryProgress的代码:
- if (v.equals(this.buttonSubBar)) {
- this.myProgressBar.setProgress(this.myProgressBar.getProgress() - 10);
- } else if (v.equals(this.buttonAddBar)) {
- this.myProgressBar.setProgress(this.myProgressBar.getProgress() + 10);
- } else if (v.equals(this.buttonSubSecondaryBar)) {
- this.myProgressBar.setSecondaryProgress(this.myProgressBar.getSecondaryProgress() - 5);
- } else if (v.equals(this.buttonAddSecondaryBar)) {
- this.myProgressBar.setSecondaryProgress(this.myProgressBar.getSecondaryProgress() + 5);
- }
5.5.2 SeekBar
图5.5.2 SeekBar
android.widget. SeekBar拖动进度条,继承自android.widget.AbsSeekBar(android.widget. ProgressBar) 。在android.widget包中。
常用属性设置:
android:max
进度条满时的值。
android:progress
进度条主进度当前值。
android:thumb
拇指跟随图标。
android:thumbOffset
设置允许的轨道的范围扩展到拇指的拇指偏移量。
方法setOnSeekBarChangeListener(SeekBar.OnSeekBarChangeListener) 可进行监听,开始拖拽,停止拖拽,以及拖拽中进度条的值是否是用户改变等参数。
- <SeekBar android:id="@+id/mySeekBar"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:thumb="@drawable/thumb"
- android:thumbOffset="10px"
- android:max="100"
- android:progress="20"/>
- this.mySeekBar = (SeekBar) super.findViewById(R.id.mySeekBar);
- this.mySeekBar.setOnSeekBarChangeListener(onSeekBarChangeListener);
- *
- *
- /**
- * seekBar 监听器
- */
- private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- myTextSeekBar.setText(progress + "");
- Log.v(CommonConfig.LOG_TAG, "SeekBar onProgressChanged, progress: " + progress + ", fromUser: " + fromUser);
- }
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- Log.v(CommonConfig.LOG_TAG, "SeekBar onStartTrackingTouch");
- }
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- Log.v(CommonConfig.LOG_TAG, "SeekBar onStopTrackingTouch");
- }
- };
5.5.3 RatingBar
图5.5.3 RatingBar
android.widget. RatingBar星式进度条,继承自android.widget.AbsSeekBar(android.widget. ProgressBar)。在android.widget包中。
常用属性设置:
android:isIndicator
是否是评级栏,指示器作用。True为指示器,用户不可操作。
android:numStars
总星数。
android:rating
当前星数。
android:stepSize
每次可以等加的最小单位。浮点数。
setOnRatingBarChangeListener(RatingBar.OnRatingBarChangeListener),添加一个监听器,可以监听每次改变。
- <RatingBar android:id="@+id/myRatingBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:isIndicator="false"
- android:numStars="5"
- android:rating="1.5"
- android:stepSize="0.5"/>
- this.myRatingBar = (RatingBar) super.findViewById(R.id.myRatingBar);
- this.myRatingBar.setOnRatingBarChangeListener(onRatingBarChangeListener);
- *
- *
- /**
- * ratingBar 监听器
- */
- private RatingBar.OnRatingBarChangeListener onRatingBarChangeListener = new RatingBar.OnRatingBarChangeListener() {
- @Override
- public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
- myTextRatingBar.setText(rating + " / " + ratingBar.getNumStars());
- Log.v(CommonConfig.LOG_TAG, "RatingBar onRatingChanged, rating: " + rating + ", fromUser: " + fromUser);
- }
- };
- 大小: 10.7 KB
- 大小: 8.3 KB
- 大小: 11.4 KB
- 基本界面控件-5进度条
- Android开发学习 之 五、基本界面控件-5进度条
- Android基本界面控件六-进度条
- Android基本界面控件
- android基本界面控件
- Android基本界面控件
- 基本界面控件
- android基本界面控件
- Android基本界面控件
- android基本控件之进度条progressBar
- Visual C++界面常用控件 之 进度条CProgress控件
- Visual C++界面常用控件 之 进度条CProgress控件
- Visual C++界面常用控件 之 进度条CProgress控件
- Android基本界面控件四-图片控件
- 基本界面控件-3图片控件
- 【Android开发学习27】界面控件之进度条(ProgressBar)
- 进度条控件
- 进度条控件
- 博客,我们是写给谁看的
- 万分简单的油画效果
- undefined reference to `__gxx_personality_v0'
- 上极限和下极限
- Struts2框架校验执行的先后顺序
- 基本界面控件-5进度条
- linux kernel
- fastboot找不到设备?一直wait for device?
- Activex、OLE、COM、OCX、DLL之间有什么区别?
- 测度论的引入
- 堆内存与栈内存小议(转载)
- PS曲线绘画翅膀素材
- 集成工具
- 运行android的SDK Manager.exe无反应