getLayoutParams().width VS setMax/MinimumWidth() for ImageView

392 views Asked by At

I do all my layout code via Java (no XML what-so-ever). However I found some peculiar behavior when setting an ImageViews height and width.

Whenever I try to set it's dimensions with .setMinimumHeight and .setMaximumHeight (using the same value), I find these values are almost never respected. The only time I get width and height to 'behave' is when I explictly set the values using getLayoutParams().width = whatever

My question is 2 parts:

  1. What is the point of having setMinimum and setMaximum if they are sporadically respected? What is the problem with using them?

  2. I find using layoutParams exhaustively verbose. I can of course override every class (a major chore since you can't Swizzle Java) but I'd like to avoid that.

Is there a way to get around having to use long lines like this

ViewGroup.LayoutParams imageParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);

_image.setLayoutParams(imageParams);

And get to this nice short syntax (without having to subclass everything, and hence my original desire to use .setMinimum/.setMaximum)

_image.setWidth(100);
0

There are 0 answers