首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

ImageSwitcher&Gallery练习题

2012-09-06 
ImageSwitcher&Gallery练习先看图再说:布局如下:View:package com.dc.adapterimport com.dc.app.Rimport

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);  

热点排行