在电话上运行平板电脑崩溃

时间:2014-03-23 15:45:01

标签: android android-layout

相同的代码在平板电脑上运行并在Galaxy手机上崩溃

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dashboard"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/icons_background"
    android:orientation="vertical" >
    <LinearLayout style="@style/dashboard_content_vertical" >
        <FrameLayout style="@style/dashboard_space_horizontal" >
        </FrameLayout>
        <LinearLayout style="@style/dashboard_content_horizontal" >
            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onMzahebClick"
                android:src="@drawable/ic_mzaheb" />
        </LinearLayout>
        <FrameLayout style="@style/dashboard_space_horizontal" />
        <LinearLayout style="@style/dashboard_content_horizontal" >
            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onFerakClick"
                android:src="@drawable/ic_ferak" />
        </LinearLayout>
        <FrameLayout style="@style/dashboard_space_horizontal" />
    </LinearLayout>
    <LinearLayout style="@style/dashboard_content_vertical" >
        <FrameLayout style="@style/dashboard_space_horizontal" />
        <LinearLayout style="@style/dashboard_content_horizontal" >
            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onHolyBookClick"
                android:src="@drawable/ic_holybook" />
        </LinearLayout>
        <FrameLayout style="@style/dashboard_space_horizontal" />
        <LinearLayout style="@style/dashboard_content_horizontal" >
            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onFactsImagePagerClick"
                android:src="@drawable/ic_facts" />
        </LinearLayout>
        <FrameLayout style="@style/dashboard_space_horizontal" />
    </LinearLayout>

    <LinearLayout style="@style/dashboard_content_vertical" >

        <FrameLayout style="@style/dashboard_space_horizontal" />

        <LinearLayout style="@style/dashboard_content_horizontal" >

            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onShbhatListClick"
                android:src="@drawable/ic_shbhat" />
        </LinearLayout>

        <FrameLayout style="@style/dashboard_space_horizontal" />

        <LinearLayout style="@style/dashboard_content_horizontal" >

            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onMapsGridClick"
                android:src="@drawable/ic_maps" />
        </LinearLayout>

        <FrameLayout style="@style/dashboard_space_horizontal" />
    </LinearLayout>

    <LinearLayout style="@style/dashboard_content_vertical" >

        <FrameLayout style="@style/dashboard_space_horizontal" >
        </FrameLayout>

        <LinearLayout style="@style/dashboard_content_horizontal" >

            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onSearchClick"
                android:src="@drawable/ic_search1" />
        </LinearLayout>

        <FrameLayout style="@style/dashboard_space_horizontal" />

        <LinearLayout style="@style/dashboard_content_horizontal" >

            <ImageView
                style="@style/dashboard_imageview"
                android:onClick="onProductsGalleryClick"
                android:src="@drawable/ic_ferak" />
        </LinearLayout>

        <FrameLayout style="@style/dashboard_space_horizontal" />
    </LinearLayout>

</LinearLayout>






<style name="dashboard_space_vertical">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">0px</item>
    <item name="android:layout_weight">1</item>
</style>

<style name="dashboard_content_vertical">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">0px</item>
    <item name="android:layout_weight">3</item>
    <item name="android:layout_gravity">center</item>
</style>

<style name="dashboard_space_horizontal">
    <item name="android:layout_width">0px</item>
    <item name="android:layout_height">fill_parent</item>
    <item name="android:layout_weight">2</item>
    <!-- <item name="android:background">@color/black</item> -->
</style>

<style name="dashboard_content_horizontal">
    <item name="android:layout_width">0px</item>
    <item name="android:layout_height">fill_parent</item>
    <item name="android:layout_weight">3</item>
    <item name="android:orientation">vertical</item>
    <item name="android:layout_gravity">center</item>
    <item name="android:gravity">center</item>
</style>

<style name="dashboard_imageview">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>
    <item name="android:layout_weight">1</item>
    <item name="android:scaleType">fitCenter</item>
</style>

这是日志活动

03-23 16:22:44.384: E/AndroidRuntime(12730): FATAL EXCEPTION: main
03-23 16:22:44.384: E/AndroidRuntime(12730): java.lang.RuntimeException: Unable to start activity ComponentInfo{rewaya.books.shiaa/rewaya.books.shiaa.HomeActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.ActivityThread.access$700(ActivityThread.java:154)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.os.Looper.loop(Looper.java:137)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.ActivityThread.main(ActivityThread.java:5306)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at java.lang.reflect.Method.invokeNative(Native Method)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at java.lang.reflect.Method.invoke(Method.java:511)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at dalvik.system.NativeStart.main(Native Method)
03-23 16:22:44.384: E/AndroidRuntime(12730): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:342)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.Activity.setContentView(Activity.java:1928)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at rewaya.books.shiaa.HomeActivity.onCreate(HomeActivity.java:43)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.Activity.performCreate(Activity.java:5255)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
03-23 16:22:44.384: E/AndroidRuntime(12730):    ... 11 more
03-23 16:22:44.384: E/AndroidRuntime(12730): Caused by: java.lang.reflect.InvocationTargetException
03-23 16:22:44.384: E/AndroidRuntime(12730):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.LayoutInflater.createView(LayoutInflater.java:593)
03-23 16:22:44.384: E/AndroidRuntime(12730):    ... 23 more
03-23 16:22:44.384: E/AndroidRuntime(12730): Caused by: java.lang.OutOfMemoryError
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.content.res.Resources.loadDrawable(Resources.java:2854)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.View.<init>(View.java:3483)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.view.ViewGroup.<init>(ViewGroup.java:446)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.widget.LinearLayout.<init>(LinearLayout.java:176)
03-23 16:22:44.384: E/AndroidRuntime(12730):    at android.widget.LinearLayout.<init>(LinearLayout.java:172)
03-23 16:22:44.384: E/AndroidRuntime(12730):    ... 26 more

1 个答案:

答案 0 :(得分:0)

在查看异常时,请始终查看“由...引起的”基础异常:

Caused by: java.lang.OutOfMemoryError 03-23 16:22:44.384: E/AndroidRuntime(12730): at     android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

你使用的位图可能很大,这可能有很多原因。

  • 您应该只使用您需要的尺寸的图像。
  • 使用png而不是bmp
  • 在android 2.3.3及以下版本上使用后调用每个位图上的recycle()
  • ...