标签:
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("停止调节");
}
}
标签:
原文地址:http://www.cnblogs.com/Defry/p/4412991.html