<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/pic"
android:src="@drawable/pic_0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:id="@+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
public class MySeekBarDemo extends Activity {
private SeekBar seekbar = null;
private ImageView pic = null;
private int picData[] = new int[] {
R.drawable.pic_0, R.drawable.pic_1,
R.drawable.pic_2, R.drawable.pic_3, R.drawable.pic_4,
R.drawable.pic_5, R.drawable.pic_6, R.drawable.pic_7,
R.drawable.pic_8, R.drawable.pic_9 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);
// 取得组件
this.seekbar = (SeekBar) super.findViewById(R.id.seekbar);
// 取得组件
this.pic = (ImageView) super.findViewById(R.id.pic);
// 0 ~ 9的范围
this.seekbar.setMax(9);
this.seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImpl());
}
private class OnSeekBarChangeListenerImpl implements SeekBar.OnSeekBarChangeListener {
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// 设置显示图片
MySeekBarDemo.this.pic
.setImageResource(MySeekBarDemo.this.picData[seekBar
.getProgress()]);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
}