我正在开发一个使用 GridView 的应用程序,并且 Gridview 中的每个图像都有一个小的描述,当我们单击任何显示此描述的图像时,我已经在不同的设备上进行了测试,它非常适合 MDPI 和 HDPI设备,但是当我在 XHDPI 设备(高分辨率设备)上对其进行测试时,出现内存不足错误。
我无法理解问题所在,这是我的活动:-
GridView gridView = (GridView) findViewById(R.id.grid_view);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(getApplicationContext()));
/**
* On Click event for Single Gridview Item
* */
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), TrafficDetails.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
这是我的 ImageAdapter,我在其中使用我的可绘制对象中的图像
public Integer[] mThumbIds = {
R.drawable.pic_1, R.drawable.pic_2,
R.drawable.pic_3, R.drawable.pic_4,
R.drawable.pic_5, R.drawable.pic_6,
R.drawable.pic_7, R.drawable.pic_8,
R.drawable.pic_9, R.drawable.pic_10,
R.drawable.pic_11, R.drawable.pic_12,
R.drawable.pic_13, R.drawable.pic_14,
R.drawable.pic_15,R.drawable.pic_16,
R.drawable.pic_17,R.drawable.pic_18,
R.drawable.pic_19,R.drawable.pic_20,
R.drawable.pic_21,R.drawable.pic_22,
R.drawable.pic_23,R.drawable.pic_24,
R.drawable.pic_25,R.drawable.pic_26,
R.drawable.pic_27,R.drawable.pic_28,
R.drawable.pic_29,R.drawable.pic_30,
R.drawable.pic_31,R.drawable.pic_32,
R.drawable.pic_33,R.drawable.pic_34,
R.drawable.pic_35,R.drawable.pic_36,
R.drawable.pic_37,R.drawable.pic_38,
R.drawable.pic_39,R.drawable.pic_40,
R.drawable.pic_41,R.drawable.pic_42,
R.drawable.pic_43,R.drawable.pic_44,
R.drawable.pic_45,R.drawable.pic_46,
R.drawable.pic_47,R.drawable.pic_48,
R.drawable.pic_49,R.drawable.pic_50,
R.drawable.pic_51,R.drawable.pic_52,
R.drawable.pic_53,
};
public String[] str_ary = {
// Description of all images
..................
};
// Constructor
public ImageAdapter(Context c){
mContext = c;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
// TextView txt = new TextView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new GridView.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
// txt.setLayoutParams(new GridView.LayoutParams(500, 500));
return imageView;
请帮我解决这个问题,任何帮助都会很明显......
谢谢