android学习笔记八——SeekBar
SeekBar——拖动条
拖动条(SeekBar)组件与ProgressBar水平形式的显示进度条类似,不过其最大的区别在于,拖动条可以由用户自己进行手工的调节,例如当用户需要调整播放器音量或者电影的播放速度都会使用到拖动条SeekBar类。
android:thumb,指定一个Drawable对象,该对象将作为自定义滑块;为了实现程序拖动滑块位置的改变,程序可以绑定一个OnSeekBarChangeListener监听器。
android:thumb,用于改变拖动条上滑块的外观。
布局文件==》
<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=".MainActivity" > <ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="200px"
android:src="@drawable/ok" /> <!-- max最大值、progress当期值 -->
<SeekBar
android:id="@+id/seekbar"
android:max="255"
android:progress="255"
android:thumb="@drawable/no"
android:layout_width="match_parent"
android:layout_height="match_parent" /> </RelativeLayout> 代码实现==》
package com.example.myseekbar; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final ImageView img = (ImageView) this.findViewById(R.id.image);
SeekBar bar = (SeekBar) this.findViewById(R.id.seekbar); bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
public void onStopTrackingTouch(SeekBar seekBar)
{ } @Override
public void onStartTrackingTouch(SeekBar seekBar)
{ } @SuppressWarnings("deprecation")
@Override
// 当拖动条的滑块位置发生改变时触发
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
img.setAlpha(progress);
}
});
} @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;
} }
android学习笔记八——SeekBar的更多相关文章
- Android学习笔记八:用Broadcast Receiver跨进程(跨app)通信
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7515194.html 在前面介绍四大组件的时候提到了可以对外部事件进行过滤的Broadcast Receive ...
- 【转】Pro Android学习笔记(九八):BroadcastReceiver(2):接收器触发通知
文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.sina.com.cn/flowingflying或作者@恺风Wei-傻瓜与非傻瓜 广播接 ...
- 【转】 Pro Android学习笔记(八八):了解Handler(2):什么是Handler
文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 之前我们有一篇很好的博文<Andro ...
- 【转】 Pro Android学习笔记(八二):了解Package(1):包和进程
文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 在之前,我们已经学习了如何签发apk,见P ...
- 【转】 Pro Android学习笔记(七八):服务(3):远程服务:AIDL文件
目录(?)[-] 在AIDL中定义服务接口 根据AIDL文件自动生成接口代码 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.n ...
- 【转】Pro Android学习笔记(二三):用户界面和控制(11):其他控件
目录(?)[-] Chronometer计时器控件 倒计时CountDownTimer Switch控件 Space控件 其他控件 Android提供了很多控件,基本上都是view的扩展. Chron ...
- udacity android 学习笔记: lesson 4 part b
udacity android 学习笔记: lesson 4 part b 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...
- Pro Android学习笔记 ActionBar(1):Home图标区
Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...
- 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView
目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...
随机推荐
- web相关问题总结 - imsoft.cnblogs
1,问题:编辑好的web程序乱码,显示不正常 解决方法:在head中加入一下代码,设置网页使用的语言为中文. <meta http-equiv="Content-Type" ...
- Ubuntu下adb的安装
1.adb简述: adb全称Android Debug Bridge,安卓调试桥接器.它是Android sdk里的一个工具,用这个工具可以直接操作管理android模拟器或者真实的andriod设备 ...
- coreseek(sphinx)安装1(xml数据源配置和测试)
1.下载coreseek-3.2.14-32版本.网址:http://www.coreseek.cn/products-install/install_on_windows/ (有详细的安装说明) ...
- Codeforces Round #310 (Div. 2) A B C
A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...
- CentOS配置LAMP环境
环境:CentOS 6.5 配置防火墙,开启80端口.3306端口 # Firewall configuration written by system-config-firewall # Manua ...
- 越狱Season 1-Episode 14: The Rat
Season 1, Episode 14: The Rat -Michael: 24 hours from now, 24小时后 my brother is scheduled to die, sch ...
- JS中的call()方法的理解
fn.call(obj,arg1,arg2);这是call()方法的使用形式,apply()是差不多的.作用是用obj对象来替换fn中的this 举个栗子: function A(){ this.co ...
- 控制文本和外观------Attr Binding(attr属性绑定)
Attr Binding(attr属性绑定) 目的 attr 绑定提供了一种方式可以设置DOM元素的任何属性值.你可以设置img的src属性,连接的href属性.使用绑定,当模型属性改变的时候,它会自 ...
- 【SDOI2008】【P1377】仪仗队
欧拉函数的应用 原题: 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是 ...
- A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)
A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python) MACHINE LEARNING PYTHON ...