0

我想在我的应用程序中插入图像开关,那么我现在该怎么办?这需要 imageadapter 那么我该如何实现呢?请帮助我..谢谢你....

这是我的代码...

Integer pics[] = { R.drawable.amrapali1, R.drawable.defic1, R.drawable.hnsafal1, R.drawable.leela1, R.drawable.mitashi1, R.drawable.magnanimous1, R.drawable.moon1, R.drawable.netpeckers1, R.drawable.nggroup1, R.drawable.platinum1, R.drawable.shivalik1, R.drawable.trikon1 };

ImageSwitcher iSwitcher;


   iSwitcher = (ImageSwitcher) findViewById(R.id.ImageSwitcher);
    iSwitcher.setFactory(this);
    iSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
            android.R.anim.fade_in));
    iSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
            android.R.anim.fade_out));

    Gallery gallery = (Gallery) findViewById(R.id.Gallery);
    gallery.setAdapter(new ImageAdapter(this));
    gallery.setOnItemClickListener(new OnItemClickListener() {
    });
4

1 回答 1

0

试试下面的ImageAdapter课程

public class ImageAdapter extends BaseAdapter {

        private Context ctx;

        public ImageAdapter(Context c) {
            ctx = c; 
        }

        public int getCount() {

            return pics.length;
        }

        public Object getItem(int arg0) {

            return arg0;
        }

        public long getItemId(int arg0) {

            return arg0;
        }

        public View getView(int arg0, View arg1, ViewGroup arg2) {

            ImageView iView = new ImageView(ctx);
            iView.setImageResource(pics[arg0]);
            iView.setScaleType(ImageView.ScaleType.FIT_XY);
            iView.setLayoutParams(new Gallery.LayoutParams(200, 150));
            return iView;
        }
    }

更详细的了解去这里

于 2014-02-05T09:35:14.917 回答