Android基础控件SeekBar拖动条的使用
1、简介
SeekBar继承ProgressBar,相关属性和三种不同状态下的触发方法:
<!--<SeekBar-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:max="100"-->
<!--android:progress="30"-->
<!--android:id="@+id/seekbar"-->
<!--android:thumb="@mipmap/ic_launcher_round"/>-->//设置滑块的
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override//进度发生改变
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
} @Override//按下
public void onStartTrackingTouch(SeekBar seekBar) {
} @Override//放开
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
2、简单使用
这是一个简单自定义的SeekBar,浅绿色是进度条颜色,红色是二级进度条颜色,黄色是背景色!
滑块的selector文件:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/seekbar_thumb_pressed" /> <item android:state_pressed="false"
android:drawable="@drawable/seekbar_thumb_normal"/>
</selector>
进度条颜色layer-list文件:layer-list创建的图形列表,也就是一个drawable 图形。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#FFFFD042" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#f23f21" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#FF96E85D" />
</shape>
</clip>
</item> </layer-list>
整体xml布局文件:
<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:gravity="center"
android:orientation="vertical"
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=".LoginActivity"> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="当前进度值:30"
android:id="@+id/textview"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekbar"
android:progress="30"
android:secondaryProgress="50"
android:maxHeight="5dp"
android:minHeight="5dp"
android:progressDrawable="@drawable/sb_bar"
android:thumb="@drawable/sb_thumb"/> </LinearLayout>
Java文件三种状态事件的触发:
public class LoginActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form. SeekBar seekBar = (SeekBar)findViewById(R.id.seekbar);
final TextView textView = (TextView)findViewById(R.id.textview);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override//进度发生改变
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
textView.setText("当前进度值:"+i);
} @Override//按下
public void onStartTrackingTouch(SeekBar seekBar) {
Toast.makeText(LoginActivity.this,"按下",Toast.LENGTH_SHORT).show();
} @Override//放开
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(LoginActivity.this,"放开",Toast.LENGTH_SHORT).show();
}
}); } }
Android基础控件SeekBar拖动条的使用的更多相关文章
- Android基础控件ProgressBar进度条的使用
1.简介 ProgressBar继承与View类,直接子类有AbsSeekBar和ContentLoadingProgressBar, 其中AbsSeekBar的子类有SeekBar和RatingBa ...
- Android基础控件ListView基础操作
1.简介 基于Android基础控件ListView和自定义BaseAdapter适配器情况下,对ListView的数据删除和添加操作: public boolean add(E e) {//添加数据 ...
- android 基础控件(EditView、SeekBar等)的属性及使用方法
android提供了大量的UI控件,本文将介绍TextView.ImageView.Button.EditView.ProgressBar.SeekBar.ScrollView.WebView ...
- android基础控件的使用
控件在屏幕上位置的确定 通常情况下控件在屏幕上确定至少要连接两条线(一条水平,一条垂直) 如下图连接了四条线 辅助线 辅助线的调出: 水平辅助线:进入activity.xml的设计模式之后如下图 为了 ...
- 矩阵, 矩阵 , Android基础控件之ImageView
天下文章大家抄,以下所有内容,有来自copy,有来自查询,亦有自己的总结(目的是总结出自己的东西),所以说原创,不合适,说是转载也不恰当,所以我称之为笔记,可惜没有此分类选项,姑且不要脸一点,选择为原 ...
- android 基础控件 EditText
EditText 简介: EditText 控件继承 TextView ,它有TextView的所有属性和方法,并且自身是可编辑的: extends TextView java.lang.Object ...
- Android 基础控件 TextView
一TextView介绍: TextView是UI最基本的组件,使用TextView可以显示丰富的文本信息.设置添加TextView最常见的方法就是在xml中添加TextView元素,并指定属性.Tex ...
- Android基础控件TextClock和Chronometer的使用
1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...
- Android基础控件单选按钮RadioButton和Checkbox复选按钮的使用
1.相关简介 RadioButton需要和RadioGroup结合使用,在RadioGroup设置布局方式! Checkbox是单独使用,本文为了方便放在了RadioGroup中! 2.简单使用 方法 ...
随机推荐
- 网页添加Live2D看板娘
看板娘简而言之就是小店的女服务生,也有“吸引顾客,招揽生意,提高人气”等作用类似品牌形象代言人的含义. 如果想放一个呆萌的看板娘在博客上 js <script type="text/j ...
- uoj118 【UR #8】赴京赶考
题目 不难发现我们直接走过去就行了 考虑到第\(i\)行的构造方法就是把\(b\)数组作为模板,每个数和\(a_i\)异或一下就可以了 于是不难发现对于一段连续相等的\(a\),它们在矩阵上就形成了完 ...
- 【2018ACM/ICPC网络赛】焦作赛区
A Magic Mirror 题目链接:https://nanti.jisuanke.com/t/31710 题意:输入字符串,如果是“Jessy”就输出“Good Guy!",否则输出“D ...
- javascript面向对象编程笔记(函数之闭包)
3 函数 3.5 闭包(closures) 3.5.1 作用域链 与很多程序设计语言不同,javascript不存在大括号级的作用域,但它有函数作用域,即在函数内定义的变量在函数外是不可见的.但如果该 ...
- Ubantu18.04安装WPS
1.去WPS官网选在合适的版本下载安装包2.在官网下载字体包3.分别右键点击安装包,选择第一项“用软件安装打开”,进行安装即可.4.此时启动应用,应该会提示系统缺失字体.5.解决字体缺失(转)
- The linux command 之网络
一.检查和检测网络 ping命令——向网络主机发送特殊数据包 [me@linuxbox ~]$ ping www.baidu.com 按Ctrl+C终止程序 tracepath——跟踪网络数据包的传输 ...
- Android开发 自定义View_白色圆型涟漪动画View
代码: import android.animation.ValueAnimator; import android.content.Context; import android.graphics. ...
- C++访问sqlite3的初体验
Sqlite确实是一个比较好的本地数据库,从接触它的时候就喜欢上了它,它可以在很多情况下简化应用.不过以前都是在Java里面使用,或者Linux C下使用的,现在有个项目(C++)可能我会用到sqli ...
- Redis-GEO
一. Redis的GEO特性 Redis3.2版本提供了GEO功能,支持存储地理位置信息用来实现诸如摇一摇,附近位置这类依赖于地理位置信息的功能.二. 命令2.1 增加地理位置信息 命令:geoadd ...
- JDK语法糖之switch字串与枚举支持
在JDK1.7之前,switch只支持byte,short,char,int,注意1.5之后的自动拆箱,对应的这四种基础类型的封装类也同样支持Byte,Short,Character,Integer, ...