Android 如何减少应用程序的大小?
在我的应用程序中,我使用54个图像。为了支持多个屏幕,我创建了如下文件夹Android 如何减少应用程序的大小?,android,android-layout,Android,Android Layout,在我的应用程序中,我使用54个图像。为了支持多个屏幕,我创建了如下文件夹 可绘制hdpi 可拉伸mdpi 可拉伸xdpi 可拉伸mdpi 并粘贴每个文件夹中的所有图像。因此,应用程序的大小增加了很多。。。。 然后我试着喜欢这种方式。。。 只取一个文件夹drawable保留所有54个图像,删除所有drawabl mdpi、drawable hdpi、drawable mdpi和drawable xdpi文件夹。 在我的清单文件中,我标注为 “” 但它给了我这样的错误 07-25 15:04:2
可绘制hdpi
可拉伸mdpi
可拉伸xdpi
可拉伸mdpi
并粘贴每个文件夹中的所有图像。因此,应用程序的大小增加了很多。。。。
然后我试着喜欢这种方式。。。
只取一个文件夹drawable保留所有54个图像,删除所有drawabl mdpi、drawable hdpi、drawable mdpi和drawable xdpi文件夹。
在我的清单文件中,我标注为
“”
但它给了我这样的错误
07-25 15:04:25.928:错误/dalvikvm堆(13963):2764800字节外部分配对此进程太大。
07-25 15:04:25.928:ERROR/GraphicsJNI(13963):VM不允许我们分配2764800字节
07-25 15:04:25.928:DEBUG/AndroidRuntime(13963):关闭虚拟机
07-25 15:04:25.928:WARN/dalvikvm(13963):threadid=1:线程退出时出现未捕获异常(组=0x4001d7e0)
07-25 15:04:25.967:错误/AndroidRuntime(13963):致命异常:主
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):java.lang.RuntimeException:无法启动活动组件信息{com.jacksonville.alenseventapp/com.jacksonville.alenseventapp.HomeActivity}:android.view.InflateException:二进制XML文件行#1:错误膨胀类
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于android.os.Handler.dispatchMessage(Handler.java:99)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于android.os.Looper.loop(Looper.java:123)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于java.lang.reflect.Method.invokenactive(本机方法)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于java.lang.reflect.Method.invoke(Method.java:521)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在dalvik.system.NativeStart.main(本机方法)
07-25 15:04:25.967:错误/AndroidRuntime(13963):由以下原因引起:android.view.InflateException:二进制XML文件行#1:膨胀类时出错
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.view.LayoutInflater.createView(LayoutInflater.java:513)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.view.LayoutInflater.inflate(LayoutInflater.java:385)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.view.LayoutInflater.充气(LayoutInflater.java:320)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于android.app.Activity.setContentView(Activity.java:1647)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于com.jacksonville.alenseventapp.HomeActivity.onCreate(HomeActivity.java:12)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-25 15:04:25.967:错误/AndroidRuntime(13963):。。。还有11个
07-25 15:04:25.967:错误/AndroidRuntime(13963):由以下原因引起:java.lang.reflect.InvocationTargetException
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.widget.LinearLayout.(LinearLayout.java:115)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于java.lang.reflect.Constructor.constructNative(本机方法)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):位于java.lang.reflect.Constructor.newInstance(Constructor.java:446)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.view.LayoutInflater.createView(LayoutInflater.java:500)
07-25 15:04:25.967:错误/AndroidRuntime(13963):。。。还有21个
07-25 15:04:25.967:错误/AndroidRuntime(13963):原因:java.lang.OutOfMemory错误:位图大小超出VM预算
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.Bitmap.nativeCreate(本机方法)上
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.Bitmap.createBitmap(Bitmap.java:468)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.Bitmap.createBitmap(Bitmap.java:435)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)上
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)上
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)上
07-25 15:04:25.967:ERROR/AndroidRuntime(13963):在android.graphics.drawable.drawable.createFromResourceStream(Drawa)上
java.lang.RuntimeException: Unable to start activity
**ComponentInfo{com.jacksonville.alenseventapp/com.
jacksonville.alenseventapp.HomeActivity}:
** android.view.InflateException: Binary XML file line #1:
Error inflating class <unknown>
07-25 15:04:25.967: ERROR/AndroidRuntime(13963):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
and 07-25 15:04:25.967: ERROR/AndroidRuntime(13963): Caused by:
android.view.InflateException: Binary XML file line #1:
Error inflating class <unknown>
07-25 15:04:25.967: ERROR/AndroidRuntime(13963): Caused by:
java.lang.reflect.InvocationTargetException
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
// here path is from where you are picking the image
Bitmap myBitmap = ShrinkBitmap(Path, 300, 300);
MyImageView.setImageBitmap(myBitmap );
private Bitmap ShrinkBitmap(String file, int width, int height) {
// TODO Auto-generated method stub
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
int heightRatio = (int)Math.ceil(bmpFactoryOptions.outHeight/(float)height);
int widthRatio = (int)Math.ceil(bmpFactoryOptions.outWidth/(float)width);
if (heightRatio > 1 || widthRatio > 1)
{
if (heightRatio > widthRatio)
{
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
bmpFactoryOptions.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(file, bmpFactoryOptions);
return bitmap;
}