--EDITED-- OMG ..我忘了看logcat。我在下面附加了日志,令人惊讶的是它内存不足。这是没有意义的,因为图像是小png的......
================================
我对下面代码的意图是在 3 x 3 矩阵中显示图像按钮。它可以很好地显示前 6 张图像,但是当我添加最后一个包含 3 张图像的线性布局时,它崩溃了。我什至无法得到错误的具体原因。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:orientation="horizontal"
android:padding="10dip"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin0"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check0"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin1"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check1"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin2"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check2"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:orientation="horizontal"
android:padding="10dip"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin3"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check3"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin4"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check4"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin5"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check5"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:orientation="horizontal"
android:padding="10dip"
>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type6"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin4"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check6"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type7"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin4"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check7"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="150dip"
android:layout_weight="1"
>
<ImageButton
android:id="@+id/background_type8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/bg_skin4"
android:scaleType="fitXY"
android:layout_margin="5dip"
android:padding="1dip"
android:background="#FFFFFF"
/>
<ImageView
android:id="@+id/background_check8"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/background_check"
android:visibility="invisible"
/>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
> 08-29 00:50:01.126: E/dalvikvm-heap(10898): Out of memory on a 5502768-byte allocation.
> 08-29 00:50:01.126: I/dalvikvm(10898): "main" prio=5 tid=1 RUNNABLE
> 08-29 00:50:01.126: I/dalvikvm(10898): | group="main" sCount=0 dsCount=0 obj=0x40c7d460 self=0x1047b48
> 08-29 00:50:01.126: I/dalvikvm(10898): | sysTid=10898 nice=0 sched=0/0 cgrp=default handle=1074947336
> 08-29 00:50:01.126: I/dalvikvm(10898): | schedstat=( 4822784373 917424823 12708 ) utm=427 stm=54 core=0
> 08-29 00:50:01.126: I/dalvikvm(10898): at android.graphics.Bitmap.nativeCreate(Native Method)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:618)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:593)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:775)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.content.res.Resources.loadDrawable(Resources.java:1968)
> 08-29 00:50:01.131: I/dalvikvm(10898): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
> 08-29 00:50:01.136: I/dalvikvm(10898): at android.widget.ImageView.<init>(ImageView.java:119)
> 08-29 00:50:01.136: I/dalvikvm(10898): at android.widget.ImageButton.<init>(ImageButton.java:85)
> 08-29 00:50:01.136: I/dalvikvm(10898): at android.widget.ImageButton.<init>(ImageButton.java:81)
> 08-29 00:50:01.136: I/dalvikvm(10898): at java.lang.reflect.Constructor.constructNative(Native Method)
> 08-29 00:50:01.136: I/dalvikvm(10898): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
> 08-29 00:50:01.141: I/dalvikvm(10898): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
> 08-29 00:50:01.141: I/dalvikvm(10898): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:283)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.Activity.setContentView(Activity.java:1892)
> 08-29 00:50:01.141: I/dalvikvm(10898): at com.Soragi.AndroidClient.Settings.BackgroundSettingActivity.onCreate(BackgroundSettingActivity.java:17)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.Activity.performCreate(Activity.java:4533)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.ActivityThread.access$600(ActivityThread.java:128)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.os.Handler.dispatchMessage(Handler.java:99)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.os.Looper.loop(Looper.java:137)
> 08-29 00:50:01.141: I/dalvikvm(10898): at android.app.ActivityThread.main(ActivityThread.java:4514)
> 08-29 00:50:01.141: I/dalvikvm(10898): at java.lang.reflect.Method.invokeNative(Native Method)
> 08-29 00:50:01.141: I/dalvikvm(10898): at java.lang.reflect.Method.invoke(Method.java:511)
> 08-29 00:50:01.141: I/dalvikvm(10898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
> 08-29 00:50:01.141: I/dalvikvm(10898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
> 08-29 00:50:01.141: I/dalvikvm(10898): at dalvik.system.NativeStart.main(Native Method)