拖动条采用拖动滑块的位置来表示数值

SeekBar的常用xml属性值:

重要的android:thumb制定一个Drawable对象,改变滑块外观

通过滑块来改变图片的透明度:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/root"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="300dp"android:src="@drawable/lijiang" />
<!--  android:thumb 是滑块的图片, android:progressDrawable是滑条的图片 --><SeekBarandroid:id="@+id/seekBar1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:max="255"android:progress="255"android:thumb="@drawable/ic_launcher" /><TextViewandroid:id="@+id/textView1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="25dp" /><TextViewandroid:id="@+id/textView2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:textSize="25dp" /></LinearLayout>

MainActivity.java

package com.example.seekbartest;import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final ImageView image =(ImageView) findViewById(R.id.imageView1);SeekBar seekbar=(SeekBar) findViewById(R.id.seekBar1);final TextView textView1 = (TextView) this.findViewById(R.id.textView1);final TextView textView2 = (TextView) this.findViewById(R.id.textView2);//设置拖动条的状态改变监听器seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){//当拖动条的滑块位置发生改变时触发该方法@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubimage.setAlpha(progress);//设置图片透明度textView1.setText("当前值:"+progress);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubtextView2.setText("拖动中...");}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubtextView2.setText("拖动完毕");}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}
}


自定义拖动条比较好,留着以后借鉴: http://blog.csdn.net/imdxt1986/article/details/7609164

星级评分条的常用xml属性:

android:isIndicator:设置该评分条是否允许用户改变(true为不允许修改)

android:numStars:设置总共有多少个星级

android:rating设置星级评分条默认的星级

android:stepSize设置没吃最少需要改变多少个星级,0.5半个星星,1就是1个星星

使用星级评分改变图片透明度:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/root"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="300dp"android:src="@drawable/lijiang" /><RatingBarandroid:id="@+id/ratingBar1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:max="255"android:numStars="6"android:progress="255"android:stepSize="0.5" /></LinearLayout>

MainActivity.java

package com.example.ratingbartest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final ImageView image =(ImageView) findViewById(R.id.imageView1);RatingBar bar=(RatingBar) findViewById(R.id.ratingBar1);//设置星级评论条状态改变监听器bar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){@Overridepublic void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser) {// TODO Auto-generated method stubimage.setAlpha((int)(rating*255/6));//设置图片透明度}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}
}

UI组件之ProgressBar及其子类(二)SeekBar拖动条和RatingBar星级评分条的使用相关推荐

  1. UI组件之 ProgressBar及其子类(一)ProgressBar进度条的使用

    ProgressBar本身进度条组件,它派生了:SeekBar和RatingBar两个组件,他们的继承关系如下: 1.ProgressBar有两个进度,一个是android:progress,另一个是 ...

  2. [Android] 星级评分条组件RatingBar

    星级评分条组件(RatingBar)一般是用来做评分,用星形来显示等级评定,它是ProgressBar的子类,继承了ProgressBar的所有属性和方法. 1.RatingBar属性 android ...

  3. UI组件之TextView及其子类(二)RadioButton和CheckBox

    单选按钮(RadioButton)和复选框(CheckBox),状态开关按钮(ToggleButton),开关(Switch)都是普通的UI组件,都继承了Button类,因此都可以用Button的各种 ...

  4. UI组件之ImageView及其子类(二)ImageButton ,ZoomButton

    从ImageButton这个字面意思上来看,它是一个图片按钮,那么我们就可以使用它做一个我们想要的图片按钮了,但是我们在实际使用的过程当中,就会发现该按钮的使用并没有想像中的那么简单,需要再增加一些代 ...

  5. UI组件之AdapterView及其子类(二)GridView网格视图的使用

    GridView网格视图属性: android:numColumns="auto_fit" --------列数设置为自动,可以为确定的数值 android:columnWidth ...

  6. UI组件之AdapterView及其子类(六)ExpandableListView组件和ExpandableListActivity的使用

    ExpandableListView是ListView的子类,他在ListView上进行了扩展,它把列表项分成了几组,每组里包含了多个列表项 ExpandableListView的列表项是由Expan ...

  7. UI组件之AdapterView及其子类(一)三种Adapter适配器填充ListView

    AdapterView的内容一般是包含多项相同格式资源的列表,常用的有5种AdapterView的子类: (1)ListView:简单的列表 (2)Spinner:下拉列表,给用户提供选择 (3)Ga ...

  8. UI组件之AdapterView及其子类(五)ListView组件和ListActivity

    ListView组件是一个显示组件,继承AdapterView基类,前面已经介绍了分别使用ArrayAdapter,SimpleAdapter,扩展BaseAdapter来为LisView提供列表项h ...

  9. UI组件之AdapterView及其子类(四)Gallery画廊控件使用

    听说 Gallery现在已经不使用了,API使用ViewPaper代替了,以后再学专研ViewPaper吧现在说说Gallery画廊,就是不停显示图片的意思 Gallery是用来水平滚动的显示一系列项 ...

最新文章

  1. Android 应用审核乱象:诈骗软件冲上排行榜首
  2. python爬虫案例讲解-Python爬虫案例集合
  3. 在c#.net通用权限管理系统组件里的 部门经理,分管副总 的管理方法参考
  4. C语言易错题集 第四部
  5. P2714-四元组统计【数论,容斥】
  6. 第一百零八期:比较容易理解的Hbase架构全解,10分钟学会,建议收藏
  7. RHEL 8 - RHEL自带AppStream应用模块管理
  8. 关于Kafka幂等producer的讨论
  9. 身体排毒,自己就可以轻松搞定 - 生活至上,美容至尚!
  10. 系泊系统悬链线matlab,孙传耀, 汤鸣晓. 基于MATLAB的系泊系统的设计及其动力分析[J]. 电子技术与软件工程, 2017(6): 62-63....
  11. rdkit Kekulize
  12. 详细解析单片机控制继电器原理图以及其作用
  13. UINO优锘:DMV架构管理可视化,让架构图管理快速升级
  14. Flink服务的HA配置
  15. 三思推荐的育儿书~~~
  16. 用Date计算日期相差多少天
  17. 生产环境服务端报错:阿里云IOT连接中断
  18. 阿里云数据库迁移遇到的问题总结
  19. 请使用netty框架实现高效稳定的websocket通信
  20. 【ML特征工程】第 2 章 :简单数字的花式技巧

热门文章

  1. 图形基础 GPU架构(2)软件调用栈
  2. C++ Primer 5th笔记(chap 18 大型程序工具)函数 try 语句块与构造函数
  3. 以太坊知识教程------账户
  4. C++(二)——命名空间(上)
  5. [GKCTF 2021]XOR
  6. 验证异常处理调用顺序
  7. SQL语法之基础查询(进阶1)and条件查询(进阶2)
  8. MySQL删除数据表(DORP TABLE语句)
  9. 【VS Code】vue.js ESLint + vscode 代码格式配置
  10. Fidder监控请求响应时间(毫秒)和请求IP