Ah,
android:adjustViewBounds="true"
is required for maxWidth to work.
Works now!
Setting adjustViewBounds
does not help if you use match_parent
, but workaround is simple custom ImageView
:
public class LimitedWidthImageView extends ImageView {
public LimitedWidthImageView(Context context) {
super(context);
}
public LimitedWidthImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public LimitedWidthImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int specWidth = MeasureSpec.getSize(widthMeasureSpec);
int maxWidth = getMaxWidth();
if (specWidth > maxWidth) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxWidth,
MeasureSpec.getMode(widthMeasureSpec));
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With