我在加载 Assets 图像时无法按比例放大它。对 BitmapDrawable(Resources, BitmapDrawable) 的新调用在 1.6 SDK 上不可用。 是否有解决方法以旧方式加载 BitmapDrawable 然后以某种方式对其进行操作?我试过调用 setTargetDensity() 无济于事。我的代码(无法正确缩放)是:
ImageView iv = (ImageView)view.findViewById(R.id.image); iv.setImageDrawable(new BitmapDrawable(view.getContext().getAssets().open(path)));
最佳答案
在做了一些不错的旧 RTFM 之后,我找到了一种有效的方法。 以下代码有效:
ImageView iv = (ImageView)view.findViewById(R.id.image); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inScaled = true; opts.inDensity = DisplayMetrics.DENSITY_MEDIUM; Rect padding = new Rect(); opts.inTargetDensity = view.getResources().getDisplayMetrics().densityDpi; Bitmap bm = BitmapFactory.decodeStream(view.getContext().getAssets().open(path), padding, opts); iv.setImageBitmap(bm);
For background see http://d.android.com/guide/practices/screens_support.html
关于android - 使用 1.6 SDK 以独立于设备和屏幕的方式将图像加载到布局 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2549548/