java.lang.OutOfMemoryError:无法分配带有4194304个空闲字节的40483812字节分配和5MB直到OOM

时间:2017-09-05 09:18:51

标签: android gridview

我有一个Gridview,其中包含很多来自我的Drawable文件夹的图片,当我打开Gridview并且我试图滚动时,应用程序因为显示上面的错误而崩溃。通过解决这个问题来帮助我,我还添加了{{1 }}和android:hardwareAccelerated="false"但它对我不起作用。谢谢提前,帮我解决这个问题。

以下是我的适配器类代码

android:largeHeap="true"

MainActivity代码就在这里

public class IndianCricketTeamAdapter extends BaseAdapter
 {
private Context mContext;
public Integer[] mThumbIds = {R.drawable.india_team1, 
R.drawable.india_team2,
        R.drawable.india_team3, R.drawable.india_team4,
        R.drawable.india_team5, R.drawable.indian_team6,
        R.drawable.indain_team7, R.drawable.india_team8, R.drawable.india_team9, R.drawable.india_team10, R.drawable.india_team11,
        R.drawable.india_team12, R.drawable.india_team13, R.drawable.india_team14};

public IndianCricketTeamAdapter(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);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(500,450));
    imageView.setPadding(8, 8, 8, 8);
    return imageView;

}
}

0 个答案:

没有答案