android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25sp" />
<TextView
android:id="@+id/tv2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25sp" />
<SeekBar
android:id="@+id/seekbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="30"
android:progressDrawable="@drawable/time_bg"
android:thumb="@drawable/ic_launcher" />
<!--
max=100,代表它的取值范围是0-100,共101个值;
progress=30,代表默认值是30
secondaryProgress="80"代表第二刻度默认值是80
progressDrawable,表示SeekBar的背景图片
thumb,表示SeekBar的滑块图片
-->
<SeekBar
android:id="@+id/seekbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50" android:secondaryProgress="80" />
</LinearLayout>
public class SeekbarActivity extends Activity implements OnSeekBarChangeListener {
private TextView tv1,tv2;
private SeekBar sb1,sb2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv1= (TextView) this.findViewById(R.id.tv1);
tv2= (TextView) this.findViewById(R.id.tv2);
sb1=(SeekBar) this.findViewById(R.id.seekbar1);
sb2=(SeekBar) this.findViewById(R.id.seekbar2);
sb1.setOnSeekBarChangeListener(this);
sb2.setOnSeekBarChangeListener(this);
}
//当前拖动状态进度
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(seekBar.getId()==R.id.seekbar1){
tv1.setText("seekbar1当前进度是:"+progress);
}else{
tv2.setText("seekbar2当前进度是:"+progress);
}
}
//开始位置
public void onStartTrackingTouch(SeekBar seekBar) {
if(seekBar.getId()==R.id.seekbar1){
tv1.setText("seekbar1开始拖动");
}else{
tv2.setText("seekbar2开始拖动");
}
}
//结束位置
public void onStopTrackingTouch(SeekBar seekBar) {
if(seekBar.getId()==R.id.seekbar1){
tv1.setText("seekbar1结束拖动");
}else{
tv2.setText("seekbar2结束拖动");
}
}
}