为什么我的布局背景是白色的?

时间:2016-12-18 10:30:25

标签: android android-layout android-studio

我创建了一个应用程序,其中我使用了一个背景活动。当我在手机中运行应用程序时,我无法看到我使用的背景,但活动正常运行,当我使用模拟器运行应用程序时:NEXUS 5,活动无法加载,应用程序崩溃。 这是logcat:

12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime: FATAL EXCEPTION: main
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime: Process: com.dexcorp.mondaydiary, PID: 3185
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dexcorp.mondaydiary/com.dexcorp.mondaydiary.ui}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:  Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.setContentView(Activity.java:2166)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.dexcorp.mondaydiary.ui.onCreate(ui.java:21)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6237)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:  Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:645)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.setContentView(Activity.java:2166) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.dexcorp.mondaydiary.ui.onCreate(ui.java:21) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6237) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:  Caused by: java.lang.reflect.InvocationTargetException
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Constructor.newInstance(Native Method)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:619)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.setContentView(Activity.java:2166) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.dexcorp.mondaydiary.ui.onCreate(ui.java:21) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6237) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:  Caused by: java.lang.OutOfMemoryError: Failed to allocate a 147456012 byte allocation with 1048576 free bytes and 63MB until OOM
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.content.res.Resources.loadDrawable(Resources.java:2540)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.View.<init>(View.java:3948)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.ViewGroup.<init>(ViewGroup.java:573)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Constructor.newInstance(Native Method) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.setContentView(Activity.java:2166) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.dexcorp.mondaydiary.ui.onCreate(ui.java:21) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6237) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.-wrap11(ActivityThread.java) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
12-18 15:50:21.031 3185-3185/com.dexcorp.mondaydiary E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

这是我使用背景的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:background="@drawable/back"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

1 个答案:

答案 0 :(得分:0)

看着你的xml我觉得你的画面,背面太大了。

当你有大图像时会发生这种类型的异常,所以检查你的背景图像是不是很大,如果是这样,那么用其他小尺寸的图像改变它,你就可以去了!