InflateException: Binary XML file line #1: Error inflating class caused by OutOfMemoryError

前端 未结 10 1602
梦如初夏
梦如初夏 2020-11-27 05:59

Here is my code:

input.xml (layout folder)



        
相关标签:
10条回答
  • 2020-11-27 06:33

    Try using images of different resolutions such as mdpi,hdpi,xhdpi if only using higher resolution images it might cause a crash in low resolution phones

    0 讨论(0)
  • 2020-11-27 06:35

    for those who have this problem: there are some cases that may lead app to crash. I have seen these the most.

    1- using ?selectableItemBackground may cause this problem.

    2- if using large images (or else) that make the application errors like failed to allocate... this happens when hardware accelerated is on. you can set it to off in this case and using large-heap in manifest(application element)

    3- if you have a drawable that is in v-21(for example) branch and you are running app on below 21, it can cause this problem too.

    good luck!

    0 讨论(0)
  • 2020-11-27 06:37

    My problem was that I had a shape with a <solid> with color ?selectableItemBackground. Yes it is dumb and a specific case, but posting it here for people with the same mistake.

    0 讨论(0)
  • 2020-11-27 06:37

    Well, in my case the answer was in xml design, conflict android:backgroundTint and android:tint

    I was design a FloatinActionButton like this:

    <android.support.design.widget.FloatingActionButton
                        android:id="@+id/fa_close_patient"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:scaleX="0.8"
                        android:scaleY="0.8"
                        android:layout_alignParentEnd="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="right"
                        android:layout_marginEnd="30dp"
                        android:backgroundTint="@color/white"
                        android:src="@drawable/ic_close_black_24dp"
                        android:tint="@color/colorPrimaryDark" />
    

    and it's ok but API > 23

    If u design for API_LEVEL < 23, this it's the fix

    <android.support.design.widget.FloatingActionButton
                        android:id="@+id/fa_close_patient"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:scaleX="0.8"
                        android:scaleY="0.8"
                        android:layout_alignParentEnd="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="right"
                        android:layout_marginEnd="30dp"
                        app:backgroundTint="@color/white"
                        android:src="@drawable/ic_close_black_24dp"/>
    

    I hope I have help you,

    Regards

    0 讨论(0)
提交回复
热议问题