Android APP開發活用範例速查大辭典(Ch0114-使用SeekBar)
GUI-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:gravity=”center” android:orientation=”vertical” >
<TextView android:id=”@+id/textview” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginBottom=”@dimen/padding_xlarge” />
<SeekBar android:id=”@+id/seekbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:progress=”50″ />
</LinearLayout>
|
程式碼片段
final TextView tv = (TextView) findViewById(R.id.textview); final SeekBar sb = (SeekBar) findViewById(R.id.seekbar); tv.setText(String.valueOf(sb.getProgress())); sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override public void onStopTrackingTouch(SeekBar seekBar) { tv.setText(“拖曳結束”); }
@Override public void onStartTrackingTouch(SeekBar seekBar) { tv.setText(“拖曳開始”); }
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv.setText(String.valueOf(progress)); } });
|