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执行结果:


更多相关文章

  1. android:padding和android:margin的区别 详解
  2. android:shrinkColumns的用法 (2011-04-21 22:12:35)
  3. android:shrinkColumns的用法 (2011-04-21 22:12:35)
  4. Android四大视图动画图文详解
  5. 将Linux下的Android签名对pk8和pem转换为Eclipse下的签名(keysto
  6. android:scrollbarStyle属性及滚动条和分割线覆盖问题
  7. android手动拖动滚动条快速滑动
  8. Android学习笔记06:线性布局LinearLayout
  9. Android学习笔记06-线性布局LinearLayout

随机推荐

  1. MySQL的Hash Join能用吗?
  2. 实战:从Mysql数据库frm文件中,提取表结构创
  3. MySQL的Bugs
  4. join为啥会阻塞主线程?
  5. 揭秘一条select语句,在MySQL中权限访问控
  6. MySQL的最低硬件要求?
  7. Linux下Shell的for循环语句N种写法
  8. MySQL8.0.20 正式发行(GA)
  9. 如何知道你创建的MySQL索引是高效,合理的
  10. 由细嫩双手引起的IT环境生产事故