How do you change the size of an ImageView?
you can do it all like
ImageView imageView = findViewById(R.id.dl_image);
imageView.getLayoutParams().width = 120;
If you're working with an existing view it can be a lot of work creating a new set of LayoutParams
from scratch. Instead - you can grab the view's existing LayoutParams, edit these, and then apply them to the view to update its LayoutParams using setLayoutParams()
ImageView imageView = findViewById(R.id.dl_image);
LayoutParams params = (LayoutParams) imageView.getLayoutParams();
params.width = 120;
// existing height is ok as is, no need to edit it
imageView.setLayoutParams(params);
Make sure you import the correct type of LayoutParams
. For this case, as you commented, you can just use the LayoutParams
of a ViewGroup
. If you were setting parameters specific to a certain type of view (e.g. alignments in RelativeLayout
s) you would have to import the LayoutParams
of that type of view.