我正在使用this回答以帮助解决我的内存不足问题。解决方案是将所有可绘制对象移动到 Assets 文件夹内的新可绘制文件夹中,并使用此功能
public static Drawable getAssetImage(Context context, String filename) throws IOException {
AssetManager assets = context.getResources().getAssets();
InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".png")));
Bitmap bitmap = BitmapFactory.decodeStream(buffer);
return new BitmapDrawable(context.getResources(), bitmap);
}
我的问题是如何在我的 Activity 中使用此功能?有这样的例子吗?
最佳答案
how do I use this function within my Activity?
嗯,因为函数是 public static
简单地说:
className.getAssetImage(this, yourDrawableName);
无需创建 instance
类(class)className (Utils)
例如:
Drawable mDrawable = Utils.getAssetImage(this, "my_drawable_image_name");
哪里mDrawable
是Drawable
返回图像。
关于java - Android 内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29081204/