简短版本:
是否有保证的最低VM预算大小(或至少是合理的目标)?我超过了它的xml布局,只不过是一个包裹单个30KB图像的线性布局。
长版:
我收到了与超出vm预算的位图相关的以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dah.rh/com.dah.rh.activities.SplashActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
at android.app.ActivityThread.access$2200(ActivityThread.java:131)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4702)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
at android.app.Activity.setContentView(Activity.java:1629)
at com.dah.rh.activities.SplashActivity.onCreate(SplashActivity.java:26)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.ImageView.<init>(ImageView.java:105)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 22 more
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.TypedArray.getDrawable(TypedArray.java:549)
at android.widget.ImageView.<init>(ImageView.java:115)
... 26 more
作为我的代码的stacktrace中的行如下:
setContentView(R.layout.splash_page);
从这里开始,Android会尝试对下面列出的资源splash_page.xml进行充气:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"/>
</LinearLayout>
图像“logo.png”是一个240x138px png,大小为30KB。我觉得这会超出预算,而其他我加载了总共超过35KB的6张图片的页面并没有超出预算。似乎我唯一能做的就是缩小图像,但我不知道它有多小。
答案 0 :(得分:0)
可以这么说,最小预算是16MB,因为Android应用程序的最小最大堆大小是16MB。使用您描述的单个PNG文件,不会超出它。