好吧,我想我有一個真正的問題需要改變。 我在Android中實現了一個gridView,按照Android開發者頁面中的說明一步步走,http://developer.android.com/resources/tutorials/views/hello-gridview.html 我改變了它,所以當點擊一個視圖時,位圖將被返回。這一切都適用於像Galxy Note和Galaxy S2這樣的高級手機,以及像Galaxy ace這樣不太先進的手機,以及2年前的一些蹩腳的HTC。但由於某些原因,由於OutOfMemory問題,它使用ICS在galaxy 3上崩潰。當在gridview上使用大約一半的圖像時,它確實有效(儘管有點慢)。這對任何人都有意義嗎?Android Galaxy Gridview在Galaxy 3上崩潰
這是我實現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
};
}
這是我的主要調用函數:
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
}
});
}
這是爲GridView的xml:
<?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"
/>
如果任何人有任何想法,我可能是錯在這裏做的,我會永遠感激
編輯:在飛機墜毀前,我在日誌中得到一個錯誤:「FimgApiStretch:彈力失敗」。另外,gridview中的滾動不起作用。這是不管事實,即使沒有足夠的縮略圖導致滾動,應用程序仍然會崩潰
你能提供logcat消息嗎? –
@Muhannad明天才有,我沒有Galaxy s3,今天也無法使用。如果我顯示實際的gridview,會有幫助嗎? –