Defry

博客园 首页 新随笔 联系 订阅 管理

1、activity_seekbar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <SeekBar
        android:id="@+id/sb"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:secondaryProgress="75" />

    <TextView
        android:id="@+id/progressText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/trackingText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

2、SeekBarActivity.java

public class SeekBarActivity extends Activity implements
        OnSeekBarChangeListener {
    // 声明相关View对象
    private SeekBar sb;
    private TextView progressText, trackingText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seekbar);
        // 取得View相关对象
        sb = (SeekBar) findViewById(R.id.sb);
        progressText = (TextView) findViewById(R.id.progressText);
        trackingText = (TextView) findViewById(R.id.trackingText);
        // *************
        sb.setOnSeekBarChangeListener(this);

    }

    // 在拖动中,即值在改变
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromTouch) {
        progressText.setText("当前值为:" + progress);
    }

    @Override
    public void onStartTrackingTouch(SeekBar arg0) {
        trackingText.setText("正在调节!");
    }

    @Override
    public void onStopTrackingTouch(SeekBar arg0) {
        trackingText.setText("停止调节");
    }

}

posted on 2015-04-09 23:39  Defry  阅读(176)  评论(0编辑  收藏  举报