银河3的android gridview的崩溃银河、android、gridview

2023-09-04 09:02:45 作者:初听桃花落

好吧,我想我有一个变化的真正的问题。 我实现了在Android的一个GridView,下面一步一步在Android开发者页面的指示,的 http://developer.android.com/resources/tutorials/views/hello-gridview.html 我改变了它,使点击视图时,该位将被退回。这一切的伟大工程上先进的手机一样Galxy注和Galaxy S2,以及后进的像银河ACE和2年前甚至有些蹩脚的HTC。但由于某些原因,它崩溃的星系3与由于内存不足的问题ICS。当在GridView控件使用约一半的图像,它的工作(虽然有点慢)。这是否任何意义的人?

Ok, I think I have a real question for a change. I implemented a gridView in Android, following step by step the instructions in the Android Developers page, http://developer.android.com/resources/tutorials/views/hello-gridview.html I changed it so that when clicking on a view, the bitmap will be returned. This all works great on advanced phones like Galxy Note and Galaxy S2, and on less advanced ones like Galaxy ace and even some crappy htc from 2 years ago. But for some reason, it crashes on galaxy 3 with ICS due to OutOfMemory issues. When using about half of the images on the gridview, it does work (albeit a bit slowly). Does this make any sense to anyone?

这是我实现ImageAdapter的:

This is my implementation of 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    
};

}

这是从我的主调用函数:

This is the calling function from my main:

  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          
        }
    });
}

这是XML的GridView的:

And this is the xml for the 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"

/>

如果任何人有任何想法,我可能会在这里做错了,我会永远感激

If anyone has any idea what I might be doing wrong here, I will be forever grateful

编辑:在飞机坠毁前,我得到的日志中的错误:FimgApiStretch:弹力失败。此外,滚动在GridView不起作用。这是不管事实,即使没有足够的缩略图引起涡旋,应用程序将仍然崩溃

Before the crash, I get an error in the log: "FimgApiStretch:stretch failed". Also, the scrolling in the gridview doesn't work. This is regardless of the fact that even if there aren't enough thumbnails to cause a scroll, the app will still crash

推荐答案

尝试,因为根据我的信息的属性值FILL_PARENT是德precated在Android 2.2及以上与match_parent取代FILL_PARENT 希望这将有助于

try to replace fill_parent with match_parent because according to my information the attribute value fill_parent is deprecated on android 2.2 and above hope this would help

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

You can see this link http://developer.android.com/training/displaying-bitmaps/load-bitmap.html I hope this will help you