什么是SeekBar?
可以拖动的进度条(在播放器中使用最常见)
1、在布局文件中声明
<SeekBar android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/seekBar" />
2、定义一个OnSeekBarChangeListener,复写其中的三个方法
SeekBar seekBar = (SeekBar)findViewById(R.id.seekBar); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { System.out.println("onStopTrackingTouch"); } @Override public void onStartTrackingTouch(SeekBar seekBar) { System.out.println("onStartTrackingTouch"); } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { System.out.println("progress : " + progress); } });
RatingBar是什么?
评论级别(显示很多星)
1、在布局文件中声明RatingBar
<RatingBar android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/ratingBar" android:numStars="5" android:stepSize="1.0" />
2、定义一个OnRatingBarChangeListener
RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar); ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { System.out.println(rating); } });