Android的加载图像高效(内存不足) [英] Android loading images efficient (out of memory)

查看:171
本文介绍了Android的加载图像高效(内存不足)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是startet为Android编写应用程序。我有3个activitys使用相同的XML布局,一个网格视图。他们还使用所有相同的适配器表现出的ImageView并在每个网格项目的TextView。当您选择的第一个活动的物体,你到了第二次,然后第三。

I just startet writing an app for Android. I have 3 activitys that use the same xml layout, an grid view. They also use all the same adapter to show an imageview and an textview in each grid item. When you select an object in the first activity, you get to the second and then to the third.

首先,我用正常的方法imageView.setImageResource(drawableid)。这是不是一个真正的问题,但是当我把更多的图像到GridView控件,我得到了内存不足的错误。

First I used the normal method "imageView.setImageResource(drawableid)". It wasn't really a problem, but when I put more images into the gridview, I got the outofmemory error.

所以我寻找一个解决方案。我试过的东西从Android开发人员站点去code位图,调整大小和异步任务等。
另一件事是毕加索库,至极将是非常简单的用Picasso.with(mContext).load(imageURI).into(ImageView的);。但毕加索IST放缓为GridView。它看起来很乱,同时滚动。有时,一些图像不会加载。

So I search for a solution. I tried the thing from the android dev site with decode bitmap, resize and Async task and so on. The other thing was the picasso library, wich would be very simple with "Picasso.with(mContext).load(imageURI).into(imageView);". But picasso ist to slow for the gridview. It looks messed up while scrolling. And sometimes some images weren't load.

所有metodes填充内存和应用程序崩溃当我打开活动几次。
我究竟做错了什么?我可以释放内存由我自己,当我离开的第一个活动到第二?

All metodes fill the memory and the app crashes when I open the activities a couple times. What am I doing wrong? Can I free up the memory by myself, when I leave the first activity to the second?

推荐答案

最好的解决办法是使用 RecyclerView 在您的应用程序
<一href=\"https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html\">https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

Best solution is use the RecyclerView in your app https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

这篇关于Android的加载图像高效(内存不足)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆