使用不同的scaleType,您可以将其放大。但是这会导致像素化和其他问题。最好使用更大的图像并缩小比例(或两个图像,全尺寸和缩略图),而不是缩放大多数图像。
编辑:好的,重读您的问题时,缩放类型是不够的。尝试使用此作为自定义视图:
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
public class HeightScaleImageView extends ImageView {
public HeightScaleImageView(Context context) {
super(context);
}
public HeightScaleImageView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public HeightScaleImageView(Context context, AttributeSet attributeSet, int defStyle) {
super(context, attributeSet, defStyle);
}
@Override
public void setImageResource(int resId) {
super.setImageResource(resId);
requestLayout();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = 0;
int height = 0;
//Scale to parent width
width = MeasureSpec.getSize(widthMeasureSpec);
Drawable drawable = getDrawable();
if (drawable != null) {
height = width * getDrawable().getIntrinsicHeight()/getDrawable().getIntrinsicWidth();
}
super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
}
我已经使用了每个缩放选项。没有用!是像素化是一个问题,但我希望这个功能在我的应用程序。因为用户可能会选择一个像素化图像。 –
@FebinMathew检查我的编辑。您是对的,缩放类型不足以将高宽比缩放为带有wrap_content高度的match_parent。上面的代码应该可以工作 –