gpt4 book ai didi

android gridview 在 Galaxy 3 上崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:00:45 25 4
gpt4 key购买 nike

好的,我想我有一个真正的问题需要改变。我在 Android 中实现了一个 gridView,一步步遵循 Android 开发者页面中的说明,http://developer.android.com/resources/tutorials/views/hello-gridview.html我更改了它,以便在单击 View 时返回位图。这一切都适用于 Galxy Note 和 Galaxy S2 等高级手机,以及 Galaxy ace 等不太先进的手机,甚至是 2 年前的一些糟糕的 htc。但由于某种原因,由于 OutOfMemory 问题,它在带有 ICS 的 galaxy 3 上崩溃。当在 gridview 上使用大约一半的图像时,它确实有效(尽管有点慢)。这对任何人都有意义吗?

这是我对 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:stretch failed”。此外,gridview 中的滚动不起作用。这与即使没有足够的缩略图导致滚动,应用程序仍然会崩溃这一事实无关

最佳答案

尝试将 fill_parent 替换为 match_parent 因为根据我的信息,属性值 fill_parent 在 android 2.2 及更高版本上已弃用希望这会有所帮助

你可以看到这个链接http://developer.android.com/training/displaying-bitmaps/load-bitmap.html希望对你有帮助

关于android gridview 在 Galaxy 3 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10999204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com