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-ListView几个比较特别的属性
  2. Android之TextView
  3. Android传感器应用
  4. Android(安卓)TextView中文字通过SpannableString来设置超链接、
  5. Android详细教程(基础篇):三十三、Android获取服务getSystemService
  6. Android底部导航栏+消息提醒
  7. Android沉浸式标题栏迄今为止最完美的解决方案
  8. Android(安卓)Layout XML属性 及 控件属性
  9. AndroidUI自动化测试工具-UIautomator

随机推荐

  1. PHP简单判断iPhone、iPad、Android及PC设
  2. Nokia N900刷android 2.3.4
  3. android广告平台介绍
  4. Android(安卓)WebView漏洞
  5. Android代码优化
  6. [百度空间] [原]跨平台编程注意事项(三):
  7. Android应用程序模型:应用程序,任务,进程,线
  8. 【Android】lib依赖
  9. android 4.4 电池电量管理底层分析(C\C+
  10. 下载并编译Chrome浏览器For Android