Android 安卓画廊崩溃
朋友们,我对画廊图片有问题。 下面是课堂:Android 安卓画廊崩溃,android,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.draw
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(新的ImageAdapter(this))
但当我尝试移动图像时崩溃。
谢谢你的帮助 你能发布你的日志跟踪以获得更好的响应吗?为什么构造函数中的
循环使用?E/AndroidRuntime(24885):致命异常:main E/AndroidRuntime(24885):java.lang.OutOfMemoryError:位图大小超过VM预算
}
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;
}
}