Ok, tôi nghĩ rằng tôi có một câu hỏi thực sự cho một sự thay đổi. Tôi đã triển khai GridView trong Android, theo từng bước hướng dẫn trong trang Nhà phát triển Android, http://developer.android.com/resources/tutorials/views/hello-gridview.html Tôi đã thay đổi nó để khi nhấp vào chế độ xem, bitmap sẽ được trả lại. Điều này tất cả các công trình lớn trên điện thoại tiên tiến như Galxy Note và Galaxy S2, và trên những cái ít tiên tiến như Galaxy ace và thậm chí một số crappy htc từ 2 năm trước đây. Nhưng vì lý do nào đó, nó bị treo trên thiên hà 3 với ICS do các vấn đề OutOfMemory. Khi sử dụng khoảng một nửa số hình ảnh trên GridView, nó hoạt động (mặc dù hơi chậm). Điều này có ý nghĩa gì với bất kỳ ai không?android gridview crashes trên Galaxy 3
Đây là triển khai thực hiện của tôi về ImageAdapter:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private int mWidth;
private int mHeight;
public ImageAdapter(Context c, int width, int height) {
mContext = c;
mWidth = width;
mHeight = height;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return mThumbIds[position];
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(mWidth, mHeight));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.third_world , R.drawable.annoyinggirl,
R.drawable.asianfather, R.drawable.awkawespeng,
R.drawable.awkpeng, R.drawable.blankdad,
R.drawable.collegesenior, R.drawable.courage,
R.drawable.frog, R.drawable.frynotsure,
R.drawable.goodguygreg, R.drawable.scumbag,
R.drawable.raptor,R.drawable.keano,
R.drawable.successkid, R.drawable.wonka,
R.drawable.braceyourselves, R.drawable.onedoesnotsimply,
R.drawable.firstworldproblem, R.drawable.amitheonlyone,
R.drawable.badluckbrian, R.drawable.interestingman,
R.drawable.toodamnhigh, R.drawable.def
};
}
Đây là chức năng gọi điện thoại từ của tôi chính:
private void changeToTemplateView(){
setContentView(R.layout.templates);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(context, (int)(dstWidth * 1.4), (int)(dstHeight * 1.4)));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Options opts = new Options();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), (int) parent.getItemIdAtPosition(position), opts);
//do stuff with bitmap
}
});
}
Và đây là xml cho GridView:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
Nếu ai có bất kỳ ý tưởng những gì tôi có thể làm sai ở đây, tôi sẽ mãi mãi biết ơn
EDIT: Trước khi vụ tai nạn, tôi nhận được một lỗi trong nhật ký: "FimgApiStretch: căng thất bại". Ngoài ra, việc cuộn trong chế độ xem lưới không hoạt động. Điều này bất kể thực tế là ngay cả khi không có đủ hình thu nhỏ để tạo cuộn, ứng dụng sẽ vẫn gặp sự cố
bạn có thể cung cấp tin nhắn logcat không? –
@Muhannad chỉ vào ngày mai, tôi không sở hữu Galaxy s3 và sẽ không có quyền truy cập vào một ngày hôm nay. Nó sẽ được giúp đỡ nếu tôi hiển thị GridView thực tế? –