ViewPager with ImageView gives quot;java.lang.OutOfMemoryError: bitmap size exceeds VM budgetquot;(带有 ImageView 的 ViewPager 给出“java.lang.OutOfMemoryError:位图大小超出 VM 预算;)
问题描述
我制作了一个 ViewPager
来显示图像.当我推进一些页面时,我得到一个 java.lang.OutOfMemoryError: bitmap size exceeded VM budget
错误.
I made a ViewPager
to display images. When I advance some pages I get an java.lang.OutOfMemoryError: bitmap size exceeds VM budget
error.
关于这个问题还有更多问题,但我没有找到解决方案(BitMap.Recycle
、System.gc()
等).如果您有任何建议或解决方案,请告诉我!
There are more questions about this issue but I did not find the solution (BitMap.Recycle
, System.gc()
etc). If you have a suggestion or solution please let me know!
PNG 为 628KB、478KB、587KB、132KB、139KB、149KB、585KB(崩溃).
The PNG's are 628KB, 478KB, 587KB, 132KB, 139KB, 149KB, 585KB (crash).
如果您有其他解决方案(滚动图像,如页面),请告诉我!
If you have an other solution (scroll images like pages) for me let met know!
我的代码:
推荐答案
在这里找到答案:Android:java.lang.OutOfMemoryError: 无法分配 23970828 字节分配,2097152 字节和 2MB 直到 OOM
只需在 AndroidManifest 内的 Application 标签中添加 android:hardwareAccelerated="false"
和 android:largeHeap="true"
即可:
Just add android:hardwareAccelerated="false"
and android:largeHeap="true"
in your Application tag inside AndroidManifest:
这篇关于带有 ImageView 的 ViewPager 给出“java.lang.OutOfMemoryError:位图大小超出 VM 预算";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!