我的应用程序中有200+ png图像。最高分辨率为1000 x 1000 is (xxhdpi)。问题是我的apk文件大小远高于50 mb,这是限制。所以,我想要制作一个可绘制的文件夹。但是在低分辨率设备上,我的图像看起来不太好。
那么,我如何在运行时调整图像大小以适应所有的小屏幕设备
如果上述方法不可能或不是一个非常有效的方法,请提出其他方法,以有效地减少apk的大小在相当程度上。
发布于 2014-03-01 07:18:52
用这种方法
public static Bitmap decodeSampledBitmapFromResource(Resources res,
int resId, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, resId, options);
}只需输入活动的资源、图像的资源id、所需的宽度和高度,此方法将返回大小调整的位图。
发布于 2014-03-01 07:15:34
你试过用
ViewTreeObserver obs = mTv.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw () { }https://stackoverflow.com/questions/22111322
复制相似问题