【Android 开发】:UI控件之拖动条控件 SeekBar的使用方法
16lz
2021-01-23
SeekBar控件可以通过拖动滑竿改变当前的值,可以利用SeekBar来设置具有一定范围的变量的值,一般用户改变屏幕亮度等。
实战案例一:
SeekBar控件使用。
布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <SeekBar android:id="@+id/seekbar1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="30" /> <SeekBar android:id="@+id/seekbar2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:progress="30" android:secondaryProgress="60" /></LinearLayout>[说明]:
android:max="100" android:progress="30"
表示最大刻度为100,进度为30
android:secondaryProgress="60"
表示第二刻度,一般用在流媒体播放视频中,第一段表示播放进度,第二段表示下载进度程序主要代码:
/* * 当滑动滑竿的时候会触发的事件(non-Javadoc) */ @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub if(seekBar.getId() == R.id.seekbar1){ textView1.setText("seekbar1的当前位置是: " + progress); }else{ textView2.setText("seekbar2的当前位置是: " + progress); } } //表示从哪里开始拖动 @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub if(seekBar.getId() == R.id.seekbar1){ textView1.setText("seekBar1开始拖动"); }else { textView1.setText("seekBar2开始拖动"); } } //表示从哪里结束拖动 @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub if(seekBar.getId() == R.id.seekbar1){ textView1.setText("seekBar1停止拖动"); }else { textView1.setText("seekBar2停止拖动"); } }程序Demo执行结果:
更多相关文章
- android多框架实现短视频应用、3D手势旋转、banner控件、指南针
- Android常用的基本控件
- [置顶] Android中以JAR形式封装控件或者类库
- 几个Android控件属性笔记
- Android显示时间和日期的控件的使用总结
- Android基础 | 控件基础 | ImageView用法
- 高级控件之网格视图(GridView)
- Android圆环控件