RatingBar:星级评分条与拖动条十分相似,它们有相同的父类:AbsSeekBar。
XML属性
|
说明
|
android:isIndicator
|
是否允许用户改变(true为不允许)
|
android:numStars
|
设置总共有多少颗星星
|
android:rating
|
设置默认星级
|
android:stepSize
|
设置每次最少需要改变多少个星级
|
布局文件:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <ImageView
- android:id="@+id/p_w_picpathi3"
- android:layout_width="fill_parent"
- android:layout_height="300px"
- android:src="@drawable/i3"
- />
- <TextView
- android:id="@+id/seektv"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_x="150dp"
- android:text="" />
- <SeekBar
- android:id="@+id/seekbar"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:max="100"
- android:progress="50"
- />
- <RatingBar
- android:id="@+id/ratingbar"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:max="100"
- android:progress="50"
- android:isIndicator="false"
- android:numStars="100"
- android:stepSize="0.05"
- />
- </LinearLayout>
利用seekbar和Ratingbar改编照片alpha值:
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.ImageView;
- import android.widget.RatingBar;
- import android.widget.SeekBar;
- import android.widget.TextView;
- import android.widget.RatingBar.OnRatingBarChangeListener;
- import android.widget.SeekBar.OnSeekBarChangeListener;
- public class AndroidtestActivity13 extends Activity {
- private ImageView iv;
- private TextView tv;
- private SeekBar sb;
- private RatingBar rb;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main13);
- iv=(ImageView) findViewById(R.id.p_w_picpathi3);
- tv=(TextView) findViewById(R.id.seektv);
- sb=(SeekBar) findViewById(R.id.seekbar);
- rb=(RatingBar) findViewById(R.id.ratingbar);
- iv.setAlpha((int) (sb.getProgress()*2.55));
- tv.setText(String.valueOf(sb.getProgress()));
- rb.setProgress(sb.getProgress());
- //sb.setOnSeekBarChangeListener(seekbarchangelistener);
- rb.setOnRatingBarChangeListener(ratingbarchangelistener);
- }
- //seekbar改变监听事件
- private OnSeekBarChangeListener seekbarchangelistener=new OnSeekBarChangeListener() {
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress,
- boolean fromUser) {
- iv.setAlpha((int) (progress*2.55));
- tv.setText(String.valueOf(progress));
- rb.setProgress(progress);
- }
- };
- //ratingbar改变监听事件
- private OnRatingBarChangeListener ratingbarchangelistener=new OnRatingBarChangeListener() {
- @Override
- public void onRatingChanged(RatingBar ratingBar, float rating,
- boolean fromUser) {
- iv.setAlpha((int) (rating*2.55));
- tv.setText(String.valueOf(rating));
- sb.setProgress((int) rating);
- }
- };
- }