评分条RatingBar和拖动条SeekBar很常见,今天来学习下。

(1)RatingBar评分条

如图:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ratingbar.MainActivity" > <RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="25dp" /> </RelativeLayout>

RatingBar监听事件:public void setOnRatingBarChangeListener (RatingBar.OnRatingBarChangeListener listener)

(2)拖动他SeekBar使用

首先从工具中拖入一个SeekBar和两个TextView,如图:

代码如下:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ratingbar.MainActivity" > <SeekBar
android:id="@+id/seekBar1"
android:max="100"
android:progress="50"
android:secondaryProgress="75"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="35dp" /> <TextView
android:id="@+id/info1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/seekBar1"
android:layout_below="@+id/seekBar1"
android:layout_marginTop="24dp"/> <TextView
android:id="@+id/info2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/info1"
android:layout_below="@+id/info1"
android:layout_marginTop="32dp"/> </RelativeLayout>

然后我们实现OnSeekBarChangeListener接口:public class MainActivity extends Activity implements OnSeekBarChangeListener{...} ,此接口共需要监听三个事件,分别是:
                 数值改变(onProgressChanged
                 开始拖动(onStartTrackingTouch
                 停止拖动(onStopTrackingTouch

完整代码如下:

 package com.example.ratingbar;

 import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; //实现OnSeekBarChangeListener接口
public class MainActivity extends Activity implements OnSeekBarChangeListener { private SeekBar sbVolumer=null;
private TextView info1=null;
private TextView info2=null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); sbVolumer = (SeekBar) findViewById(R.id.seekBar1);
sbVolumer.setOnSeekBarChangeListener(this);
info1 = (TextView) findViewById(R.id.info1);
info2 = (TextView) findViewById(R.id.info2);
} @Override
public 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;
} @Override
public 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);
} @Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) { info1.setText("当前值: " + progress);
} @Override
public void onStartTrackingTouch(SeekBar seekBar) { info2.setText("正在改变当前值");
} @Override
public void onStopTrackingTouch(SeekBar seekBar) {
info2.setText("停止拖动");
}
}

运行效果:

         

7.Android之评分条RatingBar和拖动条SeekBar学习的更多相关文章

  1. Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar

    原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...

  2. android 评分条 RatingBar 使用及自定义

    一.先上效果图片: 第一个是自定义: 第二个是原生的: 二.atingBar 介绍: RatingBar是基于SeekBar和ProgressBar的扩展,用星型来显示等级评定.使用RatingBar ...

  3. ProgressBar(进度条)、SeekBar(拖动条)与星级评分条(RatingBar)

    1.ProgressBar(进度条) (1)介绍 (2)常用属性 (3)xml代码 <ProgressBar android:id="@+id/progressBar2" s ...

  4. Android 自学之拖动条SeekBar

    拖动条(SeekBar)和进度条非常相似,只是进度条采用颜色填充来表明进度完成的程度,而拖动条则通过滑块的位置来标识数值----而且拖动条允许用户拖动滑动块来改变值,因此拖动条通常用于对系统的某种数值 ...

  5. Android 自学之星级评分条RatingBar

    星级评分条(RatingBar)与拖动条十分相似,他们还有共同的父类AbsSeekBar.实际上星级评分条和拖动条的用法和功能都十分的接近:他们都允许用户通过拖动来改变进度.RatingBar与See ...

  6. android评分条RatingBar自定义设置

    RatingBar为评分条控件,默认效果为若干个绿色的星星,如果想将其换成其他自定义图片就要自定义它的style.首先是布局文件: 其中android:numStars="5"设置 ...

  7. 更改星级评分条 RatingBar 的样式

    1.首先在布局中引用星级评分条: <RatingBar            android:id="@+id/room_ratingbar"            styl ...

  8. android自己定义进度值可拖动的seekbar

    近期忙找实习,加上实验室在推新项目,须要学习新知识.所以非常长一段时间没去整理了官博客了,github也蛮久没更新.非常羞愧.接下来还是要坚持写. 今天就简单的写一下我在项目中用到的算自己定义seek ...

  9. 评分条RatingBar Android

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

随机推荐

  1. 配置 AEM CQ6 (author + publish + apache dispatcher + ubuntu )

      AEM CQ系列是Adobe下的企业内容管理系统,现在已知的一些企业比如 Deloitte,Ford Racing,这里就不多做基本的介绍了,明白的看! 今天在Docker配置一下author i ...

  2. Android使用的Eclipse NDK开发较详细一篇文章

    转自: http://www.cnblogs.com/zdz8207/archive/2012/11/27/android-ndk-install.html

  3. Android ActionBarDrawerToggle、DrawerLayout、ActionBar 结合

    ActionBarDrawerToggle是一个开关,用于打开/关闭DrawerLayout抽屉 ActionBarDrawerToggle 提供了一个方便的方式来配合DrawerLayout和Act ...

  4. HTML5和css3的总结三

    继续总结H5的新东西 1>序列化与反序列化 序列化:其实就是一个json->string的过程 JSON.stringify(json); 反序列化:string->json的过程( ...

  5. mysqli事务处理demo

    <?php  $mysqli=new mysqli("localhost", "root", "123456", "xsph ...

  6. 富有表现力的javascript

    1.javascript的灵活性,你可以把它写的很简单,也可以写的很复杂,简直就是随心所欲: 2.javascript是弱类型语言,定义变量的时候不用声明变量类型,不声明类型,并不是说,javascr ...

  7. sass、git、ruby的安装与使用。

    安装sass时必须先安装ruby,在安装ruby时勾选Add Ruby executables to your PATH这个选项,添加环境变量,不然以后使用编译软件的时候会提示找不到ruby环境 sa ...

  8. C# 小型资源管理器

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. 点击劫持(CLICKJACKING)与X-FRAME-OPTIONS HEADER

    转载: http://www.tuicool.com/articles/mqUBfa 目录 前言 1.1 点击劫持(clickjacking attacks) 1.2  Frame Bursters. ...

  10. 0.1 hint crack

    http://files.cnblogs.com/files/crac/27.rar