首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android开发学习 之 5、基本界面控件-5进度条

2012-08-28 
Android开发学习 之 五、基本界面控件-5进度条五、基本界面控件-5进度条5.5 进度条5.5.1 ProgressBar图5.5.1

Android开发学习 之 五、基本界面控件-5进度条

五、基本界面控件-5进度条5.5 进度条5.5.1 ProgressBar

Android开发学习 之 5、基本界面控件-5进度条

图5.5.1 ProgressBar

?

android.widget. ProgressBar,继承自android.view.View 。在android.widget包中。对应对话框ProgressDialog。

ProgressBar有两种展示方式,表盘形式(普通、小、大)和条形填充形式。在layout定义时,需要通过设施style属性类设置展示方式。

?

常用属性设置:

<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

Android开发学习 之 5、基本界面控件-5进度条

图5.5.2 SeekBar

?

android.widget. SeekBar拖动进度条,继承自android.widget.AbsSeekBar(android.widget. ProgressBar) 。在android.widget包中。

?

常用属性设置:

<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() {@Overridepublic void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {myTextSeekBar.setText(progress + "");Log.v(CommonConfig.LOG_TAG, "SeekBar onProgressChanged, progress: " + progress + ", fromUser: " + fromUser);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {Log.v(CommonConfig.LOG_TAG, "SeekBar onStartTrackingTouch");}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {Log.v(CommonConfig.LOG_TAG, "SeekBar onStopTrackingTouch");}};
?

?

?

5.5.3 RatingBar

Android开发学习 之 5、基本界面控件-5进度条

图5.5.3 RatingBar

?

android.widget. RatingBar星式进度条,继承自android.widget.AbsSeekBar(android.widget. ProgressBar)。在android.widget包中。

?

常用属性设置:

<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() {@Overridepublic void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {myTextRatingBar.setText(rating + " / " + ratingBar.getNumStars());Log.v(CommonConfig.LOG_TAG, "RatingBar onRatingChanged, rating: " + rating + ", fromUser: " + fromUser);}};
?

?

 

热点排行