我有一个FragmentActivity,它在ViewPager中有5个片段。当我运行应用程序时,由于Inflate Exception而崩溃:
android.view.InflateException:二进制XML文件行#59:二进制XML文件行#59:错误导致类
如果我拿出我的ImageViews,它就不会崩溃。我不明白的是,只有5张图片(每个片段中有一张),每张只有60kb或更少。这些ImageView如何导致XML在膨胀时出错?它没有意义!
此外,问题似乎只发生在Android的某些版本上。该应用程序将在我的Note 3上运行,但不会在具有更多内存的新S6 Edge上运行。我不明白为什么会发生这种情况!
任何人都可以解释一下吗?
这是在应用崩溃时试图膨胀的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ivSplashFive"
android:scaleType="centerCrop"
android:layout_marginBottom="75dp"
android:src="@drawable/splashbeach2" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout11"
android:layout_above="@+id/llAccept">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="SEE WHAT'S GOING ON"
android:id="@+id/textView3"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:textAlignment="center"
android:textSize="16dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#fff"
android:layout_marginBottom="5dp"
android:visibility="visible" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="ANYWHERE IN THE WORLD"
android:id="@+id/textView69"
android:textAlignment="center"
android:textSize="22dp"
android:layout_gravity="center"
android:gravity="center"
android:textStyle="bold"
android:textColor="#fff"
android:layout_marginBottom="5dp"
android:visibility="visible" />
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView50"
android:scaleType="centerCrop"
android:src="@drawable/logo_white"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff"
android:layout_above="@+id/llAccept"></LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="75dp"
android:id="@+id/llAccept"
android:gravity="center"
android:visibility="visible"
android:layout_alignParentBottom="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/llSignIn"
android:visibility="visible"
android:gravity="right">
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="SIGN IN WITH FACEBOOK"
android:background="@drawable/button_fb"
android:textColor="#FFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Terms & Conditions"
android:id="@+id/textView13"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:textSize="10dp"
android:textColor="#eee"
android:textIsSelectable="false"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:layout_marginRight="15dp"
android:layout_marginBottom="90dp"
android:visibility="gone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Privacy Statement"
android:id="@+id/textView22"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="15dp"
android:textAlignment="center"
android:textSize="10dp"
android:textColor="#eee"
android:textIsSelectable="false"
android:textStyle="bold"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
android:layout_alignParentTop="false"
android:layout_marginBottom="90dp"
android:visibility="gone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:id="@+id/llLoggingIn"
android:visibility="gone"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView94"
android:scaleType="centerCrop"
android:src="@drawable/splashbeachlogo"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="170dp"
android:layout_height="170dp"
android:id="@+id/progressBar4"
android:layout_gravity="center_horizontal"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/progress2"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:id="@+id/imageView85"
android:scaleType="centerCrop"
android:src="@drawable/logo"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:id="@+id/linearLayout25"
android:paddingBottom="15dp"
android:paddingTop="5dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:layout_below="@+id/imageView85"
android:layout_marginTop="20dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="200dp"
android:layout_height="1dp"
android:background="#fff"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Welcome To DropMap"
android:id="@+id/textView168"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="14sp"
android:layout_marginLeft="3dp"
android:visibility="visible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="We are setting things up for you\nOne Moment Please"
android:id="@+id/textView169"
android:textColor="#ddd"
android:textSize="12dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:gravity="center" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Stacktrace是:
01-02 22:17:40.609 2590-2590/au.appsprout.com.dropmap W/art: Throwing OutOfMemoryError "Failed to allocate a 61440012 byte allocation with 3329648 free bytes and 3MB until OOM"
01-02 22:17:40.610 2590-2590/au.appsprout.com.dropmap E/AndroidRuntime: FATAL EXCEPTION: main
Process: au.appsprout.com.dropmap, PID: 2590
android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at au.appsprout.com.dropmap.Splash$Fragment3.onCreateView(Splash.java:208)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18788)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.v
答案 0 :(得分:0)
使用Picasso库 Picasso
Picasso.with(context)
.load(R.drawable.splashbeach2)
.resize(50, 50)
.centerCrop()
.into(imageView);