gpt4 book ai didi

java - 在 Glide 中加载更多图像时出现内存不足错误

转载 作者:搜寻专家 更新时间:2023-10-30 19:49:53 25 4
gpt4 key购买 nike

已编辑:

  • 在我的应用程序中,我在主页中加载了 300 多张图片。我使用 glide 加载图像。我收到 内存不足错误

我在 ma​​nifest 中使用了 large heap true :

android:largeHeap="true"

滑行版本:

compile 'com.github.bumptech.glide:glide:3.7.0'

设备/安卓版本:

Nexus 设备 6.0 版本

Every images I'm getting from Json would be 800kb to 1mb.

activity_layout:

<RelativeLayout
android:id="@+id/home_layout_bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/home_layout_top_recycler"
android:layout_margin="5dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_list_tab_home_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical"
android:visibility="visible" />

<TextView
android:id="@+id/no_user_posts_item_tv_recycler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rv_list_tab_home_recycler"
android:layout_marginTop="80dp"
android:layout_centerHorizontal="true"
android:text="@string/txt_no_posts_available"
android:textColor="@color/txt_common_black"
android:textSize="@dimen/txt_size" />
</RelativeLayout>

适配器代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;

final HomePostItems rowItem = getItem(position);

LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {

convertView = mInflater.inflate(R.layout.lv_adapter_post_items_layout, null);

holder = new ViewHolder();

holder.ivPostedImage = (ImageView) convertView.findViewById(R.id.iv_posted_img);


convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

..................

Glide.with(context).load(rowItem.getPosteduserpostimage())
.placeholder(R.drawable.golive_load_image).error(R.drawable.golive_cancel_image)
.override(600, 200)
.into(holder.ivPostedImage);

adapter_layout.xml:

<RelativeLayout
android:id="@+id/rl_lv_user_post_adapter_img_holder_home"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_below="@+id/tv_user_posted_msg_post_items_home" >

<ImageView
android:id="@+id/iv_posted_img_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:background="#ffffff"
android:contentDescription="@string/cont_desc"/>
</RelativeLayout>

日志:

Request threw uncaught throwable
java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Failed to allocate a 6365196 byte allocation with 865912 free bytes and 845KB until OOM
at java.util.concurrent.FutureTask.report(FutureTask.java:94)
at java.util.concurrent.FutureTask.get(FutureTask.java:164)
at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor.afterExecute(FifoPriorityThreadPoolExecutor.java:96)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1121)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 6365196 byte allocation with 865912 free bytes and 845KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
at com.bumptech.glide.load.resource.bitmap.Downsampler.decodeStream(Downsampler.java:329)
at com.bumptech.glide.load.resource.bitmap.Downsampler.downsampleWithSize(Downsampler.java:220)
at com.bumptech.glide.load.resource.bitmap.Downsampler.decode(Downsampler.java:153)
at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:50)
at com.bumptech.glide.load.resource.bitmap.StreamBitmapDecoder.decode(StreamBitmapDecoder.java:19)
at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:39)
at com.bumptech.glide.load.resource.bitmap.ImageVideoBitmapDecoder.decode(ImageVideoBitmapDecoder.java:20)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeBitmapWrapper(GifBitmapWrapperResourceDecoder.java:121)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decodeStream(GifBitmapWrapperResourceDecoder.java:94)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:71)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:61)
at com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperResourceDecoder.decode(GifBitmapWrapperResourceDecoder.java:22)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromSourceData(DecodeJob.java:190)
at com.bumptech.glide.load.engine.DecodeJob.decodeSource(DecodeJob.java:177)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromSource(DecodeJob.java:128)
at com.bumptech.glide.load.engine.EngineRunnable.decodeFromSource(EngineRunnable.java:122)
at com.bumptech.glide.load.engine.EngineRunnable.decode(EngineRunnable.java:101)
at com.bumptech.glide.load.engine.EngineRunnable.run(EngineRunnable.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
at com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor$DefaultThreadFactory$1.run(FifoPriorityThreadPoolExecutor.java:118)

我不知道如何解决这个 OOM 问题。如果您已经熟悉这个问题,请分享您的建议。

最佳答案

  • 我通过移除嵌套的 ScrollView 解决了这个问题回收站 View 。为什么发生 OutOfMemory 错误意味着,加载更多时主页中有超过 200 张图片,它正在加载所有 200 张图片,因为使用recyclerview 上方的嵌套 ScrollView 。

  • 所以我无法在logcat image view width and height中一一检查适配器。

  • 移除嵌套 ScrollView 后修复了内存不足错误。因为它回家时只会加载设备中显示的 3 张图像 Activity 。

  • 同时检查 this ,如何使用滚动而不是嵌套 ScrollView 。

关于java - 在 Glide 中加载更多图像时出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38560637/

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