SeekBar拖动条控件
一、简介
1、
二、SeekBar拖动条控件使用方法
1、创建SeekBar控件
2、添加setOnSeekBarChangeListener监听
seekBar2.setOnSeekBarChangeListener(this);
三、代码实例
1、效果图:
2、代码
fry.Activity01
1 package fry; 2 3 import com.example.SeekBarDemo1.R; 4 5 import android.app.Activity; 6 import android.os.Bundle; 7 import android.widget.SeekBar; 8 import android.widget.SeekBar.OnSeekBarChangeListener; 9 import android.widget.TextView;10 import android.widget.Toast;11 12 public class Activity01 extends Activity implements OnSeekBarChangeListener{13 private TextView textView1;14 private TextView textView2;15 private SeekBar seekBar1;16 private SeekBar seekBar2;17 @Override18 protected void onCreate(Bundle savedInstanceState) {19 // TODO Auto-generated method stub20 super.onCreate(savedInstanceState);21 setContentView(R.layout.activity01);22 textView1=(TextView) findViewById(R.id.TextView1_seekBar);23 textView2=(TextView) findViewById(R.id.TextView2_seekBar);24 seekBar1=(SeekBar) findViewById(R.id.SeekBar1);25 seekBar2=(SeekBar) findViewById(R.id.SeekBar2);26 seekBar1.setOnSeekBarChangeListener(this);27 seekBar2.setOnSeekBarChangeListener(this);28 }29 /*30 * onProgressChanged:进度条改变事件31 * onStartTrackingTouch:进度条开始拖动事件32 * onStopTrackingTouch:进度条停止拖动事件33 * (non-Javadoc)34 * @see android.widget.SeekBar.OnSeekBarChangeListener#onProgressChanged(android.widget.SeekBar, int, boolean)35 */36 @Override37 public void onProgressChanged(SeekBar seekBar, int progress,38 boolean fromUser) {39 // TODO Auto-generated method stub40 if(seekBar1.getId()==R.id.SeekBar1){41 Toast.makeText(this, "1111111", Toast.LENGTH_SHORT).show();42 textView1.setText("seekBar1当前位置:"+progress);43 }else{44 textView2.setText("seekBar2当前位置:"+progress);45 }46 }47 @Override48 public void onStartTrackingTouch(SeekBar seekBar) {49 // TODO Auto-generated method stub50 if(seekBar1.getId()==R.id.SeekBar1){51 textView1.setText("seekBar1开始拖动");52 }else{53 textView2.setText("seekBar2开始拖动:");54 }55 }56 @Override57 public void onStopTrackingTouch(SeekBar seekBar) {58 // TODO Auto-generated method stub59 if(seekBar1.getId()==R.id.SeekBar1){60 textView1.setText("seekBar1停止拖动");61 }else{62 textView2.setText("seekBar2停止拖动:");63 }64 }65 }
/SeekBarDemo1/res/layout/activity01.xml
1 26 7 13 19 20 26 27 33 34 35 36
四、获得
1、设置初始进度条
android:progress="30"
2、设置setOnSeekBarChangeListener监听
seekBar1.setOnSeekBarChangeListener(this);
3、onProgressChanged:进度条改变事件
4、onStartTrackingTouch:进度条开始拖动事件
5、onStopTrackingTouch:进度条停止拖动事件