Android放置图片内存溢出处理方法
程序员文章站
2022-05-01 17:45:36
app\src\main\res\mipmap-hdpi,不要放进drawable文件夹)
xml version="1.0" encoding="utf-8&...
app\src\main\res\mipmap-hdpi,不要放进drawable文件夹)
xml version="1.0" encoding="utf-8"> <framelayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:app="https://schemas.android.com/apk/res-auto" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".framelayoutapp" imageview android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="406dp" app:srccompat="@mipmap/photos" android:layout_gravity="center" imageview android:id="@+id/imageview2" android:layout_width="206dp" android:layout_height="179dp" android:layout_gravity="center" app:srccompat="@mipmap/pictures" /> framelayout>
方法二(将图片放入app\src\main\res\drawable时)
xml version="1.0" encoding="utf-8"> <framelayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:app="https://schemas.android.com/apk/res-auto" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".framelayoutapp" imageview android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="406dp" app:srccompat="@drawable/photos" android:layout_gravity="center" imageview android:id="@+id/imageview2" android:layout_width="206dp" android:layout_height="179dp" android:layout_gravity="center" app:srccompat="@drawable/pictures" /> framelayout>
会出现内存溢出问题
关于java.lang.outofmemoryerror: failed to allocate a 127844364 byte allocation with 16768792 free bytes and 63mb until oom
在androidmanifest中的application加入以下代码:
android:hardwareaccelerated="false" android:largeheap="true" //申请更多的内存