【发布时间】:2012-12-20 15:16:22
【问题描述】:
所以我在 listview 中有一个 imageView(由 Loader 加载),并且宽度设置为 match_parent。当我想设置 imageview 位图时,我使用 imageView 的高度和宽度来加载最佳大小的位图。问题是 ImageView 大小有时在 Loader bindView 中是未知的(尚未测量?)。在这种情况下,我怎么能每次都得到位图的宽度?
@Override
public void bindView(View view, final Context context, Cursor cursor) {
ImageView iv = (ImageView) (ImageView) view.findViewById(R.id.image);
....
bitmap = BitmapHelper.decodeSampledBitmapFromFile( new File(file), iv.getWidth(), iv.getHeight());
imageView.setImageBitmap(bitmap);
}
【问题讨论】:
-
为什么需要提供尺寸来创建位图?您可以只使用原始位图并在 ImageView 上设置适当的 scaleType,对吗?
-
我有大图像,我想在内存中加载小位图以避免 OOM。 Android training - Load a Scaled Down Version into Memory