我希望图像在我的应用程序中流动

时间:2014-02-05 08:29:25

标签: android imageswitcher

我想在我的应用程序中插入图像swicther所以我现在该怎么办? 这是图像适配器,所以我该如何实现它? 请帮我.. 谢谢你....

这是我的代码......

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() {
    });

1 个答案:

答案 0 :(得分: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;
        }
    }

如需更详细的了解,请转到HERE