Android之进度条
Android之进度条
ProgressBar有垂直风格与水平风格之分
SeekBar与RatingBar是ProgressBar的子类
XML部分:
<!--如果不设置style风格,则默认为垂直风格的进度条-->
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="150"
android:progress="75"
android:secondaryProgress="100"
style="?android:attr/progressBarStyleHorizontal"
/>
<!―设置进度条、当前进度条、第二进度条-->
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/progressbar"
android:max="100"
android:progress="50"
android:secondaryProgress="60"
/>
<!--numstars星星个数stepSize每次跨的长度-->
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1"
android:layout_below="@id/seekBar"
/>
Java部分:
publicclassMainActivityextendsActivity{
privateProgressBarprogressBar;
privateSeekBarseekBar;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar=(ProgressBar)findViewById(R.id.progressbar);
//判断属于哪种进度条,是水平的还是垂直的风格
booleanb=progressBar.isIndeterminate();
//设置第一进度条与第二进度条每次增加的值
progressBar.incrementProgressBy(15);
progressBar.incrementSecondaryProgressBy(20);
SeekBarListenerlistener=newSeekBarListener();
seekBar.setOnSeekBarChangeListener(listener);
}
classSeekBarListenerimplementsOnSeekBarChangeListener{
//progress当前SeekBar的进度
@Override
publicvoidonProgressChanged(SeekBarseekBar,intprogress,
booleanfromUser){
//TODOAuto-generatedmethodstub
System.out.println("progress"+fromUser);
}
@Override
publicvoidonStartTrackingTouch(SeekBarseekBar){
//TODOAuto-generatedmethodstub
System.out.println("start");
}
@Override
publicvoidonStopTrackingTouch(SeekBarseekBar){
//TODOAuto-generatedmethodstub
System.out.println("stop");
}
}
更多相关文章
- ExpandableListView设置选中child的背景
- Android中的AnimationDrawable的使用
- Android小问题解决办法记录
- Android(安卓)App 权限一点知识
- Android(安卓)小说阅读护眼模式
- Android(安卓)获取系统设置参数。
- Android(安卓)代码设置来电铃声
- Android(安卓)RingtoneManager铃声管理
- android中设置activity的出现方式