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 开发】:UI控件之拖动条控件 SeekBar的使用方法_第1张图片【Android 开发】:UI控件之拖动条控件 SeekBar的使用方法_第2张图片

更多相关文章

  1. android多框架实现短视频应用、3D手势旋转、banner控件、指南针
  2. Android常用的基本控件
  3. [置顶] Android中以JAR形式封装控件或者类库
  4. 几个Android控件属性笔记
  5. Android显示时间和日期的控件的使用总结
  6. Android基础 | 控件基础 | ImageView用法
  7. 高级控件之网格视图(GridView)
  8. Android圆环控件

随机推荐

  1. Android中常见的热门标签的流式布局的实
  2. Android进度条 多线程登录或下载
  3. Android心得4.1--文件的保存与读取及文件
  4. .如何避免Android内存泄漏
  5. Android(安卓)NDK C++开发注意事项总结
  6. Android(安卓)再爆新漏洞,9.0 以下所有手
  7. android 开发如何获得第三方应用Widget的
  8. Android(安卓)中读取Excel文件实例详解
  9. Android基于Pull方式解析xml的方法详解
  10. android中采用Pull解析XML文档