RatingBar:星级评分条与拖动条十分相似,它们有相同的父类:AbsSeekBar

星级评分条:

XML 属性 说明
android:isIndicator 是否允许用户改变 (true 为不允许 )
android:numStars 设置总共有多少颗星星
android:rating 设置默认星级
android:stepSize 设置每次最少需要改变多少个星级

布局文件:

        
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <ImageView
  8. android:id="@+id/imagei3"
  9. android:layout_width="fill_parent"
  10. android:layout_height="300px"
  11. android:src="@drawable/i3"
  12. />
  13. <TextView
  14. android:id="@+id/seektv"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:layout_x="150dp"
  18. android:text=""/>
  19. <SeekBar
  20. android:id="@+id/seekbar"
  21. android:layout_width="fill_parent"
  22. android:layout_height="wrap_content"
  23. android:max="100"
  24. android:progress="50"
  25. />
  26. <RatingBar
  27. android:id="@+id/ratingbar"
  28. android:layout_width="fill_parent"
  29. android:layout_height="wrap_content"
  30. android:max="100"
  31. android:progress="50"
  32. android:isIndicator="false"
  33. android:numStars="100"
  34. android:stepSize="0.05"
  35. />
  36. </LinearLayout>

利用seekbar和Ratingbar改编照片alpha值:

        
  1. importandroid.app.Activity;
  2. importandroid.os.Bundle;
  3. importandroid.widget.ImageView;
  4. importandroid.widget.RatingBar;
  5. importandroid.widget.SeekBar;
  6. importandroid.widget.TextView;
  7. importandroid.widget.RatingBar.OnRatingBarChangeListener;
  8. importandroid.widget.SeekBar.OnSeekBarChangeListener;
  9. publicclassAndroidtestActivity13extendsActivity{
  10. privateImageViewiv;
  11. privateTextViewtv;
  12. privateSeekBarsb;
  13. privateRatingBarrb;
  14. @Override
  15. publicvoidonCreate(BundlesavedInstanceState)
  16. {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.main13);
  19. iv=(ImageView)findViewById(R.id.imagei3);
  20. tv=(TextView)findViewById(R.id.seektv);
  21. sb=(SeekBar)findViewById(R.id.seekbar);
  22. rb=(RatingBar)findViewById(R.id.ratingbar);
  23. iv.setAlpha((int)(sb.getProgress()*2.55));
  24. tv.setText(String.valueOf(sb.getProgress()));
  25. rb.setProgress(sb.getProgress());
  26. //sb.setOnSeekBarChangeListener(seekbarchangelistener);
  27. rb.setOnRatingBarChangeListener(ratingbarchangelistener);
  28. }
  29. //seekbar改变监听事件
  30. privateOnSeekBarChangeListenerseekbarchangelistener=newOnSeekBarChangeListener(){
  31. @Override
  32. publicvoidonStopTrackingTouch(SeekBarseekBar){
  33. }
  34. @Override
  35. publicvoidonStartTrackingTouch(SeekBarseekBar){
  36. }
  37. @Override
  38. publicvoidonProgressChanged(SeekBarseekBar,intprogress,
  39. booleanfromUser){
  40. iv.setAlpha((int)(progress*2.55));
  41. tv.setText(String.valueOf(progress));
  42. rb.setProgress(progress);
  43. }
  44. };
  45. //ratingbar改变监听事件
  46. privateOnRatingBarChangeListenerratingbarchangelistener=newOnRatingBarChangeListener(){
  47. @Override
  48. publicvoidonRatingChanged(RatingBarratingBar,floatrating,
  49. booleanfromUser){
  50. iv.setAlpha((int)(rating*2.55));
  51. tv.setText(String.valueOf(rating));
  52. sb.setProgress((int)rating);
  53. }
  54. };
  55. }

本文出自 “个人笔记” 博客,谢绝转载!

更多相关文章

  1. Android事件拦截机制
  2. 一点见解: Android事件分发机制(三)
  3. Android中的多击事件
  4. 关于android 双击事件
  5. Android触屏事件和MotionEvent介绍
  6. Android事件分发机制及如何解决事件冲突

随机推荐

  1. 深度好文 |Matplotlib 可视化最有价值的 5
  2. Oracle基本操作+Java连接Oracle
  3. Python英语 - Issue16
  4. 思科dhcp和链路捆绑
  5. 2019年1-5月文章汇总 | Python数据之道
  6. Android中的UI线程详解
  7. 可视化神器 Plotly Express 合并到 Plotl
  8. JVM的新生代跟老年代
  9. 用Python快速分析和预测股票价格
  10. 机器学习爱好者必读的入门指南