android 通过滚动条改变图片显示_第1张图片

在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) {

}

}

}

更多相关文章

  1. Android的TCP Socket连接组件
  2. android 图片水平显示,类Gallery效果
  3. 【Android】View组件
  4. Android界面编程——Android高级UI组件(三)
  5. android 图片旋转
  6. android基础学习--->Android SharedPreferences存储对象和图片(An
  7. Android根据Button状态(normal,focused,pressed)显示不同背景图
  8. Android 高清加载巨图方案 拒绝压缩图片

随机推荐

  1. android中expandablelistview的学习
  2. Android 拖拽滑动(OnDragListener和ViewDr
  3. android九宫格锁屏控件
  4. android 点击空白 隐藏软键盘
  5. Android笔记(1)---Android开发环境的搭建
  6. android获取图片和视频的缩略图
  7. Android Wear 进阶 - 3 Creating Custom
  8. Android中文API——ScrollView
  9. android圆形有边框无背景色
  10. Android指示灯控制