SeekBar拖动条控件

一、简介

1、

二、SeekBar拖动条控件使用方法

1、创建SeekBar控件

<SeekBar
android:id="@+id/SeekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="30"
/>

2、添加setOnSeekBarChangeListener监听

seekBar2.setOnSeekBarChangeListener(this);

三、代码实例

1、效果图:

2、代码

fry.Activity01

 package fry;

 import com.example.SeekBarDemo1.R;

 import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast; public class Activity01 extends Activity implements OnSeekBarChangeListener{
private TextView textView1;
private TextView textView2;
private SeekBar seekBar1;
private SeekBar seekBar2;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity01);
textView1=(TextView) findViewById(R.id.TextView1_seekBar);
textView2=(TextView) findViewById(R.id.TextView2_seekBar);
seekBar1=(SeekBar) findViewById(R.id.SeekBar1);
seekBar2=(SeekBar) findViewById(R.id.SeekBar2);
seekBar1.setOnSeekBarChangeListener(this);
seekBar2.setOnSeekBarChangeListener(this);
}
/*
* onProgressChanged:进度条改变事件
* onStartTrackingTouch:进度条开始拖动事件
* onStopTrackingTouch:进度条停止拖动事件
* (non-Javadoc)
* @see android.widget.SeekBar.OnSeekBarChangeListener#onProgressChanged(android.widget.SeekBar, int, boolean)
*/
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if(seekBar1.getId()==R.id.SeekBar1){
Toast.makeText(this, "1111111", Toast.LENGTH_SHORT).show();
textView1.setText("seekBar1当前位置:"+progress);
}else{
textView2.setText("seekBar2当前位置:"+progress);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(seekBar1.getId()==R.id.SeekBar1){
textView1.setText("seekBar1开始拖动");
}else{
textView2.setText("seekBar2开始拖动:");
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(seekBar1.getId()==R.id.SeekBar1){
textView1.setText("seekBar1停止拖动");
}else{
textView2.setText("seekBar2停止拖动:");
}
}
}

/SeekBarDemo1/res/layout/activity01.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/TextView1_seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView1"
/>
<TextView
android:id="@+id/TextView2_seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView2"
/> <SeekBar
android:id="@+id/SeekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="30"
/> <SeekBar
android:id="@+id/SeekBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="60"
/> </LinearLayout>

四、获得

1、设置初始进度条

android:progress="30"

2、设置setOnSeekBarChangeListener监听

seekBar1.setOnSeekBarChangeListener(this);

3、onProgressChanged:进度条改变事件

4、onStartTrackingTouch:进度条开始拖动事件

5、onStopTrackingTouch:进度条停止拖动事件

最新文章

  1. maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener
  2. SAP NWBC for HTML and Desktop configuration steps[From sdn]
  3. VC C运行时库(CRTL)的几个版本及选用
  4. Android GPS应用:临近警告
  5. C# .NET 逻辑层的框架设计
  6. B计划
  7. Oracle数据库(一)概述、基础与简单操作
  8. linux内核自旋锁API
  9. 补习系列(1)-springboot项目基础搭建课
  10. Mybatis(二,三)
  11. Bitmap BitmapData
  12. Delphi XE2有什么新功能
  13. 蓝牙inquiry流程之Inquiry Complete处理
  14. Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
  15. vmware下虚拟机不能上网问题解决
  16. ERROR 1045 (28000): Access denied for user &#39;ODBC&#39;@&#39;localhost&#39; (using password: N O) MYSQL
  17. html -- &lt;meta name=&quot;viewport&quot;/&gt;
  18. 把大象装进冰箱的N种方法
  19. 语音-数字中继-E1-学习帖
  20. css效果小计

热门文章

  1. Spring 的IOC容器之注解的方式
  2. 洛谷 [BJOI2012]最多的方案
  3. pandas 报错:【sys:1: DtypeWarning: Columns (15) have mixed types. Specify dtype option on import or set low_memory=False.】
  4. 使用 Python 编写 vim 插件
  5. Codeforces Round #245 (Div. 1)——Xor-tree
  6. 关于source insight、添加.s和.S文件,显示全部路径、加入项目后闪屏幕
  7. Tensorflow 学习笔记(一)TensorFlow入门
  8. Python(递归)
  9. js, 树状菜单隐藏显示
  10. Spring.Net依赖注入(属性注入)