在LinearLayout中ldpi mdpi屏幕大小出错

时间:2014-06-03 17:35:14

标签: android android-layout android-linearlayout

错误:

06-03 23:11:19.090: E/AndroidRuntime(1767): FATAL EXCEPTION: main
06-03 23:11:19.090: E/AndroidRuntime(1767): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multi/com.example.multi.MainActivity}: android.view.InflateException: Binary XML file line #382: Error inflating class <unknown>
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.os.Looper.loop(Looper.java:137)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.ActivityThread.main(ActivityThread.java:5039)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at java.lang.reflect.Method.invokeNative(Native Method)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at java.lang.reflect.Method.invoke(Method.java:511)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at dalvik.system.NativeStart.main(Native Method)
06-03 23:11:19.090: E/AndroidRuntime(1767): Caused by: android.view.InflateException: Binary XML file line #382: Error inflating class <unknown>
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.Activity.setContentView(Activity.java:1881)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at com.example.multi.MainActivity.onCreate(MainActivity.java:88)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.Activity.performCreate(Activity.java:5104)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-03 23:11:19.090: E/AndroidRuntime(1767):     ... 11 more
06-03 23:11:19.090: E/AndroidRuntime(1767): Caused by: java.lang.reflect.InvocationTargetException
06-03 23:11:19.090: E/AndroidRuntime(1767):     at java.lang.reflect.Constructor.constructNative(Native Method)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-03 23:11:19.090: E/AndroidRuntime(1767):     ... 24 more
06-03 23:11:19.090: E/AndroidRuntime(1767): Caused by: java.lang.OutOfMemoryError
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.View.<init>(View.java:3328)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.view.ViewGroup.<init>(ViewGroup.java:431)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.widget.LinearLayout.<init>(LinearLayout.java:176)
06-03 23:11:19.090: E/AndroidRuntime(1767):     at android.widget.LinearLayout.<init>(LinearLayout.java:172)
06-03 23:11:19.090: E/AndroidRuntime(1767):     ... 27 more

382代码行在这里:

 <LinearLayout
        android:id="@+id/pizding2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@drawable/bg"
        android:orientation="vertical" 
        android:layout_weight="1"
        android:visibility="invisible"
        >

但它适用于hpdi和xhdpi以及xxhdpi屏幕吗?为什么这个错误仅在ldpi和mdpi中出现?

但是当我删除“android:background =”@ drawable / bg“时,它说:

    06-03 23:14:00.796: E/AndroidRuntime(1845): FATAL EXCEPTION: main
06-03 23:14:00.796: E/AndroidRuntime(1845): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multi/com.example.multi.MainActivity}: android.view.InflateException: Binary XML file line #417: Error inflating class <unknown>
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.os.Looper.loop(Looper.java:137)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.ActivityThread.main(ActivityThread.java:5039)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at java.lang.reflect.Method.invokeNative(Native Method)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at java.lang.reflect.Method.invoke(Method.java:511)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at dalvik.system.NativeStart.main(Native Method)
06-03 23:14:00.796: E/AndroidRuntime(1845): Caused by: android.view.InflateException: Binary XML file line #417: Error inflating class <unknown>
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.Activity.setContentView(Activity.java:1881)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at com.example.multi.MainActivity.onCreate(MainActivity.java:88)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.Activity.performCreate(Activity.java:5104)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-03 23:14:00.796: E/AndroidRuntime(1845):     ... 11 more
06-03 23:14:00.796: E/AndroidRuntime(1845): Caused by: java.lang.reflect.InvocationTargetException
06-03 23:14:00.796: E/AndroidRuntime(1845):     at java.lang.reflect.Constructor.constructNative(Native Method)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-03 23:14:00.796: E/AndroidRuntime(1845):     ... 26 more
06-03 23:14:00.796: E/AndroidRuntime(1845): Caused by: java.lang.OutOfMemoryError
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.content.res.Resources.loadDrawable(Resources.java:1965)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.View.<init>(View.java:3328)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.view.ViewGroup.<init>(ViewGroup.java:431)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.widget.LinearLayout.<init>(LinearLayout.java:176)
06-03 23:14:00.796: E/AndroidRuntime(1845):     at android.widget.LinearLayout.<init>(LinearLayout.java:172)
06-03 23:14:00.796: E/AndroidRuntime(1845):     ... 29 more

417行在这里:

  <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/koniec_czasu_box"
                android:gravity="center"
                android:orientation="horizontal" >

这意味着我的布局案例中的每个drawable都是一个exepction:

<LinearLayout
    android:id="@+id/pizding2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:visibility="invisible"
    android:background="@drawable/bg"
    android:orientation="vertical" 

    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_gravity="center"
        android:layout_marginBottom="80dp"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:layout_weight="2"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/koniec"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"

            android:background="@null"
            android:src="@drawable/koniec_czasu_bez_boxa" 
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/koniec_czasu_box"
            android:gravity="center"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/twojwynik"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:text="0"
                    android:textSize="20sp"
                    android:textColor="#ffffff" />

            </LinearLayout>


        </LinearLayout>

        <ImageButton
            android:id="@+id/zagraj_odnowa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/klik_reset2" />

        <ImageButton
            android:id="@+id/najlepszy_wynik"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/klik__naj_wynik" />

        <ImageButton
            android:id="@+id/backmenu2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_weight="1"
            android:background="@null"
            android:scaleType="fitCenter"
            android:src="@drawable/klik_do_menu" />
    </LinearLayout>

</LinearLayout>

0 个答案:

没有答案