SeekBar拖动条控件

SeekBar拖动条控件

一、简介

1、

SeekBar拖动条控件

二、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、效果图:

SeekBar拖动条控件

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:进度条停止拖动事件

上一篇:table数据表格添加checkbox进行数据进行两个表格左右移动。


下一篇:AX2012导Demo数据