SeekBar:
SeekBar是进度条。我们使用进度条时,可以使用系统默认的进度条;也可以自定义进度条的图片和滑块图片等。
RatingBar
评分条,与拖动条类似
用星星表示进
度
示例:
<ImageView
android:id="@+id/imageView2"
android:layout_width="300dp"
android:layout_height="300dp"
app:srcCompat="@drawable/img1"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="368dp"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
android:max="255"
android:progress="255"
app:layout_constraintTop_toBottomOf="@+id/imageView2"/>
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="0dp"
android:numStars="5"
android:stepSize="0.5"
android:rating="5"
app:layout_constraintTop_toBottomOf="@+id/seekBar"/>
//setpSize是最少的单位是多少
//numStarts是星星数量
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView imageView = (ImageView)findViewById(R.id.imageView2);
final SeekBar seekBar = (SeekBar)findViewById(R.id.seekBar);
final RatingBar ratingBar = (RatingBar)findViewById(R.id.ratingBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
imageView.setImageAlpha(i);
ratingBar.setRating(i*5.0f/255);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
imageView.setImageAlpha((int)v*255/5);
seekBar.setProgress((int)v*255/5);
//设置SeekBar的值
}
});
}
}