android 通过滚动条改变图片显示
在main.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" >
<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>
在MySeekBarDemo.java程序中
package com.tarena.seekbar;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
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); //取得组件
this.seekbar.setMax(9); //拖动条为0~9的范围
this.seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImpl());
}
private class OnSeekBarChangeListenerImpl implements OnSeekBarChangeListener{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
MySeekBarDemo.this.pic
.setImageResource(MySeekBarDemo.this.picData[seekBar
.getProgress()]); //设置显示图片
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
}
更多相关文章
- Android的TCP Socket连接组件
- android 图片水平显示,类Gallery效果
- 【Android】View组件
- Android界面编程——Android高级UI组件(三)
- android 图片旋转
- android基础学习--->Android SharedPreferences存储对象和图片(An
- Android根据Button状态(normal,focused,pressed)显示不同背景图
- Android 高清加载巨图方案 拒绝压缩图片