- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在编写一个与 Facebook 集成的应用程序。我的应用程序可以选择显示好友列表。
列表中的每一项都有一个ProfilePictureView
:
<com.facebook.widget.ProfilePictureView
android:id="@+id/fli_profilePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:is_cropped="true"
app:preset_size="small" />
然后列表适配器将用户的 id 设置到每个项目的 ProfilePictureView
中:
ProfilePictureView profilePicture = (ProfilePictureView) view.findViewById(R.id.fli_profilePicture);
profilePicture.setProfileId(friendsList.get(position).getId());
但是这样一来,如果滚动过多,ListView
会抛出 OutOfMemoryError。
是不是因为 ProfilePictureView
下载了大版本的个人资料图片,然后只将它们缩小了?如果可以,如何设置只下载小尺寸的图片?
或者还有其他方法可以解决这个问题吗?
谢谢
最佳答案
您可能应该通过缩小下载的图像来减少内存消耗
private Bitmap decodeFile(File f){
try {
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=70;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
这里有一个很好的教程,可以在 ListView 中下载图像 http://www.technotalkative.com/android-asynchronous-image-loading-in-listview/
希望对你有帮助:)
关于android - (Android)(Facebook) 多个 ProfilePictureViews 导致 OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18182146/
我正在尝试将用户提供的经纬度值与数据库中的经纬度值进行比较。如果它们在彼此半径 15 公里内,则应更改 TextView 。但我面临以下错误, 我的数据库包含值 source lat = 19.218
我在我的应用程序中使用改造来下载一些媒体文件,如视频、mp3、jpg、pdf 等。当我想下载一个 55MB 的 mp4 格式的大文件时,这是一个问题。当我想下载这个文件时,我收到这样的错误: OutO
所以我正在创建一个 Android 应用程序,这段代码引发了 "Caused by: java.lang.OutOfMemoryError: OutOfMemoryError thrown while
直到昨天,我的应用程序运行良好,但我所做的是,由于某些原因,我不得不在 Android Studio 中打开具有不同工作空间的同一个应用程序。从那时起,当我尝试运行该应用程序时,我遇到了以下异常,所以
我正在尝试构建一个应用程序,其中客户端将其屏幕发送到服务器,客户端仅在上次发送屏幕和最新捕获的屏幕之间存在差异时才发送其屏幕(以便该程序在网络)。服务器使用 JFrame 和 JLabel 来显示图像
我正在尝试使用内存映射模式在 cupy 中加载一些较大的 .npy 文件,但我不断遇到 OutOfMemoryError 。 我认为,由于它是在内存映射模式下打开的,因此此操作不应该占用太多内存,因为
我正在尝试对基于 ant 的(Netbeans RCP)项目进行分级并找到奇怪的分级行为。 我用探查器做了一些观察,得到了下一个结果。 环境配置 Gradle 1.9 Build time: 20
我有一个应用程序可以进行网络调用并检索 XML 数据。如果没有太多数据,下面的代码可以正常工作。 public class WebClient { private static final S
在我的应用程序中,我每 3 分钟刷新一次数据。如果应用程序可以工作几个小时,我会遇到这样的错误: java.lang.OutOfMemoryError at org.apache.http.util.
我在我的一个应用程序中偶尔收到 OutOfMemoryError: (Heap Size=49187KB, Allocated=41957KB)。我该怎么做才能诊断? 01-09 10:32:02
对于学校项目,我必须编写不同类型的算法。问题是,我得到了一个工作算法。但是我必须多次运行它,一段时间后它给了我以下错误: Exception in thread "main" java.lang.Ou
这个问题在这里已经有了答案: 8年前关闭。 Possible Duplicate: Recursive function causing a stack overflow 完成示例惰性序列 here
我收到 java.lang.OutOfMemoryError 错误,即使我还有足够的空闲 RAM。我进行的内存转储在 200MB 到 1GB 之间,而我的服务器有 24GB 的 RAM。我设置了 -X
我不明白为什么这段代码没有OutOfMemoryError public static void main(String[] args) { Object[] ref = new Object
我正在使用这个语句 //some code int a[][]=new int[5000000][5000000]; //some code 并使用命令运行它 java -mx512m Test 它给
今天我在玩OOM错误,我发现了一些我自己无法解释的东西。 我尝试分配一个比堆大的数组,期望 “请求的阵列大小超出 VM 限制”错误,但我得到一个“ Java 堆空间 ”错误。 根据JDK 11 doc
我有一个显示图像的简单页面。来源是 URL var img = new Image (); var source = new UriImageSource { Uri =
我有一个 Java Spring Boot 应用程序。它是一个非常大的应用程序,具有许多服务,并且可以执行大量任务。我尝试实现的新任务之一是从 Oracle DB 读取一些数据并通过 REST 将其发
我正在尝试使用流读取一个非常大的文件,因此我需要并行流而不是每行迭代...我正在尝试如下: String cont = new String(Files.readAllBytes(Paths.get(
假设我们的最大内存为 256M,为什么这段代码可以工作: public static void main(String... args) { for (int i = 0; i < 2; i++)
我是一名优秀的程序员,十分优秀!