Android画廊崩溃

时间:2013-07-21 04:51:03

标签: android

朋友们,我对图库图片有疑问。 这是班级:

Integer[] pics = {
    R.drawable.prod1,
        R.drawable.prod2,
        R.drawable.prod3,
        R.drawable.prod4, 
            R.drawable.prod5,
            R.drawable.prod6,
            R.drawable.prod7,
            R.drawable.prod8
};

图库ga =(图库)findViewById(R.id.Gallery01);         ga.setAdapter(new ImageAdapter(this));

}


public class ImageAdapter extends BaseAdapter {

    private Context ctx;
    int imageBackground;

    public ImageAdapter(Context c) {
        ctx = c;
        TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
        imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
        ta.recycle();
    }

    @Override
    public int getCount() {

        return pics.length;
    }

    @Override
    public Object getItem(int arg0) {

        return arg0;
    }

    @Override
    public long getItemId(int arg0) {

        return arg0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        ImageView iv = new ImageView(ctx);
        iv.setImageResource(pics[arg0]);
        iv.setScaleType(ImageView.ScaleType.FIT_XY);
        iv.setLayoutParams(new Gallery.LayoutParams(150,120));
        iv.setBackgroundResource(imageBackground);
        return iv;
    }

}

但是当我尝试移动图像时崩溃了。 谢谢你的帮助。

0 个答案:

没有答案