Android的SeekBar和RateBar的使用-android学习之旅(三十二)
SeekBar简介
SeekBar允许用户拖动,进行调节经常用于音量调节等方面。
android:thumb设置drawable对象来表示拖动的物体。
setOnSeekBarChangeListener()设置SeekBar的改变。
代码示例
package peng.liu.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.SeekBar;
public class MainActivity extends Activity {
private ImageView image;
private SeekBar seekBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.image);
seekBar = (SeekBar) findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
image.setAlpha(i);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
布局代码
<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="240px"
android:id="@+id/image"
android:src="@drawable/ic_launcher"
android:scaleType="fitXY"/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:max="255"
android:progress="255"
/>
</LinearLayout>
效果图
RatingBar简介
RatingBar是一个星级评分条,它和SeekBar有着相同的父类AbsSeekBar,因此属性相似。
RatingBar属性
代码示例
package peng.liu.test;
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.SeekBar;
public class MainActivity extends Activity {
private ImageView image;
private RatingBar ratingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
image = (ImageView) findViewById(R.id.image);
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
image.setAlpha(v*255/5);
}
});
}
}
<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="240px"
android:id="@+id/image"
android:src="@drawable/ic_launcher"
android:scaleType="fitXY"/>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:max="255"
android:progress="255"
android:numStars="5"
android:stepSize="0.5"/>
</LinearLayout>
效果图
Android的SeekBar和RateBar的使用-android学习之旅(三十二)的更多相关文章
- Android广播接收器Broadcast Receiver-android学习之旅(十二)
首先继承BroadcastReceiver类,并在manifest中注册 public class MyReceiver extends BroadcastReceiver { public MyRe ...
- Android使用局和数据实现天气项目-android学习之旅(十二)
1.首先注册聚合数据账号,下载相应的sdk 2.导入jar包和 so文件 配置Application,初始化sdk <application //自己新建的application类 androi ...
- Android四大组件之一Service介绍-android学习之旅(十二)
基本概念: service是android四大组件之一,运行在后台执行耗时操作,并不提供用户界面.其他组件如acticity可以通过startService启动该组件,也可以通过bindService ...
- (转载)Android项目实战(三十二):圆角对话框Dialog
Android项目实战(三十二):圆角对话框Dialog 前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话 ...
- Android UI开发第三十二篇——Creating a Navigation Drawer
Navigation Drawer是从屏幕的左侧滑出,显示应用导航的视图.官方是这样定义的: The navigation drawer is a panel that displays the ap ...
- Android的RadioButton和checkBox的用法-android学习之旅(十九)
RadioButton和checkBox简介 单选按钮(RadioButton)和复选框(CheckBox)都继承了Button,因此属性的设置和Button差不多,只是加了一个android:che ...
- android布局Relative和gridLayout-android学习之旅(十六)
Relative布局简介 相对布局的组件是由兄弟组件和父组价决定的,因此这种布局被称为相对布局. 属性设置介绍 RelativeLayout.Layoutparam中只能设置为true和false的属 ...
- android布局##TableLayout和FrameLayout-android学习之旅(十五)
TableLayout 表格布局 tablelayout简介 表格布局有TableLayout代表,但是它的本质定义仍然是线性管理器.表格布局采用行和列来管理UI,但是不需要明确的定义多少行,多少列, ...
- Android项目实战(三十二):圆角对话框Dialog
前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话框的"确定"按钮 难点:1.对话框边框圆角 ...
随机推荐
- 使用JdbcTemplate 操作PostgreSQL,当where条件中有timestamp类型时,报错operator does not exist: timestamp w/out timezone
今天遇到一个问题,找了还半天,Google一下,官网显示是一个bug. 思考一番肯定是类型出了问题. Controller: Service:转化时间戳 Dao: 一波转换搞定!
- Java正则过滤
import java.util.regex.Matcher; import java.util.regex.Pattern; public class LongStringtonumber { pu ...
- struts2 可以用ognl拿到值而不可以用el拿到值的解决方法
错误debug后 得到了There is no read method for container的错误 于是我new了一个实体类 package com.unity; public class St ...
- JVM常见问题(二)
6. GC收集器有哪些?它们的特点是? 常见的GC收集器如下图所示,连线代表可搭配使用: 1.Serial收集器(串行收集器) 用于新生代的单线程收集器,收集时需要暂停所有工作线程(Stop the ...
- Python小代码_7_字符串的字符次数统计
生成包含 1000 个随机字符的字符串,并统计每个字符出现的次数. import string import random #获取字符 x = string.ascii_letters + strin ...
- SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页
前言 本篇文章主要讲述的是SpringBoot整合Mybatis.Druid和PageHelper 并实现多数据源和分页.其中SpringBoot整合Mybatis这块,在之前的的一篇文章中已经讲述了 ...
- Python3 条件控制
if 语句 Python中if语句的一般形式如下所示: if condition_1: statement_block_1 elif condition_2: statement_block_2 el ...
- Matlab—regexp正则表达式
原文转自:http://blog.csdn.net/yf210yf/article/details/42421523 关于正则表达式的基本知识 正则表达式就是一个表达式(也是一串字符),它定义了某种字 ...
- MySQL连接及基本信息查看命令小结
前言 学习PHP就不得不提MySQL,虽然有phpMyadmin这样的工具可以图形化操作数据库,但我还是想借学习PHP的机会使用下命令行方式操作数据库.以下就是我的学习小结,包括命令行连接数据库,查看 ...
- Twitter 架构优化之路--Twitter是如何做到每秒处理3000张图片的
如今,Twitter每秒可以创建并保存3000张(20GB)的图片.2015年,Twitter甚至从对媒体存储策略的优化中节省出了600万美元. 但并非一开始就是这样的,2012年Twitter还主要 ...