【Android(安卓)开发】:UI控件之拖动条控件 SeekBar的使用方法
16lz
2021-12-04
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:padding和android:margin的区别 详解
- android:shrinkColumns的用法 (2011-04-21 22:12:35)
- android:shrinkColumns的用法 (2011-04-21 22:12:35)
- Android四大视图动画图文详解
- 将Linux下的Android签名对pk8和pem转换为Eclipse下的签名(keysto
- android:scrollbarStyle属性及滚动条和分割线覆盖问题
- android手动拖动滚动条快速滑动
- Android学习笔记06:线性布局LinearLayout
- Android学习笔记06-线性布局LinearLayout