大家好,我使用ImageView显示图片的时候,设置的属性:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
使用资源:
mImageView.setImageResource(R.drawable.image);
和直接使用图片:
mImageView.setImageBitmap(BitmapFactory.decodeResource(R.drawable.image));
两者在手机上显示的大小不一致。
请问这是为什么?谢谢大家。
android:layout_width="wrap_content"
android:layout_height="wrap_content"
使用资源:
mImageView.setImageResource(R.drawable.image);
和直接使用图片:
mImageView.setImageBitmap(BitmapFactory.decodeResource(R.drawable.image));
两者在手机上显示的大小不一致。
请问这是为什么?谢谢大家。
private Bitmap decodeResource(Resources resources, int id) {
TypedValue value = new TypedValue();
resources.openRawResource(id, value);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inTargetDensity = value.density;
return BitmapFactory.decodeResource(resources, id, opts);
}