标签:com 应用 horizon att line bsp 讲解 演示 seekbar
本文简述在Android开发中进度条(ProgressBar)的常见应用,仅供学习分享使用。
在Android开发中,进度条的使用场景有很多,如播放电影时可拖动的观看进度条,评分时使用的评分条,上传下载时的进度条,网络加载时的圆形进度条等。本文主要讲解三种进度条的常见用法:ProgressBar,SeekBar,RatingBar。
ProgressBar涉及知识点
ProgressBar效果图如下图所示:
ProgressBar示例代码:
1 <LinearLayout 2 android:id="@+id/ll_progress" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:layout_below="@id/ll_seeking" 6 android:layout_marginTop="8dp" 7 android:layout_marginRight="15dp" 8 android:orientation="horizontal"> 9 <TextView 10 android:id="@+id/tv_progress" 11 android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:text="@string/progress1" 14 android:textSize="20dp"/> 15 <ProgressBar 16 android:id="@+id/pb_01" 17 android:max="100" 18 android:progress="30" 19 android:layout_marginLeft="10dp" 20 android:secondaryProgress="40" 21 style="?android:attr/progressBarStyleHorizontal" 22 android:layout_weight="1" 23 android:layout_width="0dp" 24 android:layout_height="40dp"/> 25 </LinearLayout> 26 <TextView 27 android:id="@+id/tv_progress2" 28 android:layout_width="wrap_content" 29 android:layout_height="wrap_content" 30 android:layout_below="@id/ll_progress" 31 android:layout_marginTop="8dp" 32 android:text="@string/progress2" 33 android:textSize="20dp"/> 34 <ProgressBar 35 android:id="@+id/pb_02" 36 android:layout_alignLeft="@id/rbar" 37 android:layout_below="@id/ll_progress" 38 style="?android:attr/progressBarStyleLarge" 39 android:layout_width="wrap_content" 40 android:layout_height="wrap_content"/>
SeekBar涉及知识点
SeekBar效果图如下图所示:
SeekBar示例代码
1 //监控SeekBar事件 2 mSeekBar=(SeekBar)this.findViewById(R.id.sbar); 3 mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 4 @Override 5 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 6 Log.i("DemoBar", "SeekBar-->setOnSeekBarChangeListener: "+String.valueOf(progress)+"-->fromUser:"+String.valueOf(fromUser)); 7 mSeekText.setText(String.valueOf(progress)); 8 } 9 10 @Override 11 public void onStartTrackingTouch(SeekBar seekBar) { 12 13 } 14 15 @Override 16 public void onStopTrackingTouch(SeekBar seekBar) { 17 18 } 19 });
RatingBar涉及知识点
RatingBar效果图如下图所示:
RatingBar示例代码
1 mRatingBar =(RatingBar) this.findViewById(R.id.rbar); 2 mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { 3 @Override 4 public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { 5 Log.i("DemoBar", "RatingBar-->onRatingChanged: "+String.valueOf(rating)+"-->fromUser:"+String.valueOf(fromUser)); 6 mRatingText.setText(String.valueOf(rating)); 7 } 8 });
一起学习,一起总结,一起进步。附上整体演示图片
标签:com 应用 horizon att line bsp 讲解 演示 seekbar
原文地址:https://www.cnblogs.com/hsiang/p/10225368.html