SeekBar拖动条的使用

<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/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结束拖动");
}
}
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值