ImageSwitcher&Gallery练习
先看图再说:
布局如下:
View:package com.dc.adapter;import com.dc.app.R;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;public class ImageAdapter extends BaseAdapter {Context context;public Integer[] images={R.drawable.icon,R.drawable.image_0,R.drawable.image_1,R.drawable.image_2,R.drawable.image_3,R.drawable.image_4,R.drawable.image_5,R.drawable.image_6,R.drawable.image_7,R.drawable.image_8,R.drawable.image_9,};public ImageAdapter(Context context){this.context=context;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn images.length;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubImageView imageView=new ImageView(context);imageView.setImageResource(images[position]);//imageView.setLayoutParams(new Gallery.LayoutParams(120, 100));imageView.setMaxWidth(120);imageView.setMaxHeight(100);imageView.setAdjustViewBounds(true);imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);return imageView;}}
1 楼 tifang 2011-08-31 我用这个代码的时候会报错, switcher.setFactory(this);