我正在尝试在我的应用程序上设置一个背景,该背景可以在平板电脑和手机上很好地扩展。所以我得到了一个尺寸为 2560 x 1600 但只有 44k 大小的 png 背景。但是,每次我运行该应用程序时,我都会不断收到此信息。
08-08 14:50:21.251: E/AndroidRuntime(2924): FATAL EXCEPTION: main
08-08 14:50:21.251: E/AndroidRuntime(2924): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.reflap.reflap/com.reflap.reflap.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.os.Looper.loop(Looper.java:137)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-08 14:50:21.251: E/AndroidRuntime(2924): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 14:50:21.251: E/AndroidRuntime(2924): at java.lang.reflect.Method.invoke(Method.java:525)
08-08 14:50:21.251: E/AndroidRuntime(2924): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-08 14:50:21.251: E/AndroidRuntime(2924): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-08 14:50:21.251: E/AndroidRuntime(2924): at dalvik.system.NativeStart.main(Native Method)
08-08 14:50:21.251: E/AndroidRuntime(2924): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
08-08 14:50:21.251: E/AndroidRuntime(2924): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-08 14:50:21.251: E/AndroidRuntime(2924): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.Activity.setContentView(Activity.java:1895)
08-08 14:50:21.251: E/AndroidRuntime(2924): at com.reflap.reflap.MainActivity.onCreate(MainActivity.java:18)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.Activity.performCreate(Activity.java:5133)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-08 14:50:21.251: E/AndroidRuntime(2924): ... 11 more
08-08 14:50:21.251: E/AndroidRuntime(2924): Caused by: java.lang.reflect.InvocationTargetException
08-08 14:50:21.251: E/AndroidRuntime(2924): at java.lang.reflect.Constructor.constructNative(Native Method)
08-08 14:50:21.251: E/AndroidRuntime(2924): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
08-08 14:50:21.251: E/AndroidRuntime(2924): ... 24 more
08-08 14:50:21.251: E/AndroidRuntime(2924): Caused by: java.lang.OutOfMemoryError
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.content.res.Resources.loadDrawable(Resources.java:2105)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.widget.ImageView.<init>(ImageView.java:127)
08-08 14:50:21.251: E/AndroidRuntime(2924): at android.widget.ImageView.<init>(ImageView.java:117)
08-08 14:50:21.251: E/AndroidRuntime(2924): ... 27 more
我不明白这么小的尺寸怎么会出现内存不足的情况。
这是我的 imageview 布局 xml
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="@drawable/back" />