7.Android之评分条RatingBar和拖动条SeekBar学习
评分条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学习的更多相关文章
- Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar
原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...
- android 评分条 RatingBar 使用及自定义
一.先上效果图片: 第一个是自定义: 第二个是原生的: 二.atingBar 介绍: RatingBar是基于SeekBar和ProgressBar的扩展,用星型来显示等级评定.使用RatingBar ...
- ProgressBar(进度条)、SeekBar(拖动条)与星级评分条(RatingBar)
1.ProgressBar(进度条) (1)介绍 (2)常用属性 (3)xml代码 <ProgressBar android:id="@+id/progressBar2" s ...
- Android 自学之拖动条SeekBar
拖动条(SeekBar)和进度条非常相似,只是进度条采用颜色填充来表明进度完成的程度,而拖动条则通过滑块的位置来标识数值----而且拖动条允许用户拖动滑动块来改变值,因此拖动条通常用于对系统的某种数值 ...
- Android 自学之星级评分条RatingBar
星级评分条(RatingBar)与拖动条十分相似,他们还有共同的父类AbsSeekBar.实际上星级评分条和拖动条的用法和功能都十分的接近:他们都允许用户通过拖动来改变进度.RatingBar与See ...
- android评分条RatingBar自定义设置
RatingBar为评分条控件,默认效果为若干个绿色的星星,如果想将其换成其他自定义图片就要自定义它的style.首先是布局文件: 其中android:numStars="5"设置 ...
- 更改星级评分条 RatingBar 的样式
1.首先在布局中引用星级评分条: <RatingBar android:id="@+id/room_ratingbar" styl ...
- android自己定义进度值可拖动的seekbar
近期忙找实习,加上实验室在推新项目,须要学习新知识.所以非常长一段时间没去整理了官博客了,github也蛮久没更新.非常羞愧.接下来还是要坚持写. 今天就简单的写一下我在项目中用到的算自己定义seek ...
- 评分条RatingBar Android
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
随机推荐
- GitHub入门之二 参与一个项目编写
接上文:大多数时候我们也需要把别人的代码进行整合和修改,而不是简单的修改,这时就需要对一个项目进行修改. 注意,本系列文章主要说明在github网站上的操作,更多高级操作请使用git控制台 一.for ...
- 研:手势与眼动相结合-手势SDK的整合
Leap提供了SDK.但是整合有很多的问题,写博客记录一下: 写一个类:SampleListener.cpp以及头文件SampleListener.h. 这里主要碰到的问题是找不到以及冲突问题: 这里 ...
- 21Mybatis_订单商品数据模型_一对多查询——resultMap方式
这篇文章延续订单商品数据模型,这张讲述的是一对多的查询.(用resultMap) 给出几张表的内容: User表:
- struts2中简单的文件上传
2016-08-31 一. 文件上传 利用commons-fileupload-1.2.1.jar实现简单的上传文件,首先在页面上填写表单,记得加上enctype="multip ...
- Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- bisController
public class BisController : Controller { // // GET: /Bis/ protected string GetJson(object obj) { Is ...
- caffe windows 学习第一步:编译和安装(vs2012+win 64)
没有GPU,没有linux, 只好装caffe的windows版本了. 我的系统是win10(64位),vs 2012版本,其它什么都没有装,因此会需要一切的依赖库. 其实操作系统只要是64位就行了, ...
- [CareerCup] 3.3 Set of Stacks 多个栈
3.3 Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in ...
- [CareerCup] 4.3 Create Minimal Binary Search Tree 创建最小二叉搜索树
4.3 Given a sorted (increasing order) array with unique integer elements, write an algorithm to crea ...
- C# GC 垃圾回收机制
今天来谈谈C# 的GC ,也就是垃圾回收机制,非常的受教,总结如下 首先:谈谈托管,什么叫托管,我的理解就是托付C# 运行环境帮我们去管理,在这个运行环境中可以帮助我们开辟内存和释放内存,开辟内存一般 ...