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部分:
publicclass MainActivity extends Activity {
private ProgressBar progressBar;
private SeekBar seekBar;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar=(ProgressBar)findViewById(R.id.progressbar);
//判断属于哪种进度条,是水平的还是垂直的风格
booleanb=progressBar.isIndeterminate();
//设置第一进度条与第二进度条每次增加的值
progressBar.incrementProgressBy(15);
progressBar.incrementSecondaryProgressBy(20);
SeekBarListener listener=new SeekBarListener();
seekBar.setOnSeekBarChangeListener(listener);
}
class SeekBarListener implements OnSeekBarChangeListener{
//progress当前SeekBar的进度
@Override
publicvoidonProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
System.out.println("progress"+ fromUser);
}
@Override
publicvoid onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
System.out.println("start");
}
@Override
publicvoid onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
System.out.println("stop");
}
}