在我的 android 项目中,有带有图像的自定义网格视图。图片来自资产文件夹。
这是从资产文件夹获取可绘制的代码:
Drawable imgDrawable = Drawable.createFromStream(myContext.getAssets().open(imgPath),null);
滚动网格视图后,它给出内存异常日志显示:
01-10 05:24:32.492: E/AndroidRuntime(2303): FATAL EXCEPTION: main
01-10 05:24:32.492: E/AndroidRuntime(2303): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.graphics.drawable.Drawable.createFromStream(Drawable.java:657)
01-10 05:24:32.492: E/AndroidRuntime(2303): at org.Infoware.BookShelf.BookShelfActivity$BookshelfAdapter.getView(BookShelfActivity.java:331)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.AbsListView.obtainView(AbsListView.java:1439)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.GridView.makeAndAddView(GridView.java:1222)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.GridView.makeRow(GridView.java:268)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.GridView.fillDown(GridView.java:221)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.GridView.fillGap(GridView.java:188)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:3569)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:3067)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.os.Handler.handleCallback(Handler.java:587)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.os.Handler.dispatchMessage(Handler.java:92)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.os.Looper.loop(Looper.java:130)
01-10 05:24:32.492: E/AndroidRuntime(2303): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-10 05:24:32.492: E/AndroidRuntime(2303): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 05:24:32.492: E/AndroidRuntime(2303): at java.lang.reflect.Method.invoke(Method.java:507)
01-10 05:24:32.492: E/AndroidRuntime(2303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850)
01-10 05:24:32.492: E/AndroidRuntime(2303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
01-10 05:24:32.492: E/AndroidRuntime(2303): at dalvik.system.NativeStart.main(Native Method)