On the fragment there are several ImageView and Button. When you click on Button, you need to resize the ImageView (that is, the component itself). All markup in RelativeLayout.

I am trying to achieve results in the following way:

int width = myImageView.getWidth() + 100; int height = myImageView.getHeight() + 100; myImageView.setLayoutParams(new RelativeLayout.LayoutParams(width, height)); 

When you click on the Button, the size of the ImageView successfully increases. With repeated clicks, there are no results, i.e. ImageView sizes no longer change. Which way to look?

  • It seems that you were sealed up and your dimensions should be taken and assigned to one widget, and not two - YuriySPb
  • @Yuriy spb thanks for the comment. Overworked with simplification of a code for an example. Dimensions are taken from the desired widget - Alexander Tkachenko
  • try calling myImageView.invalidate () at the very end - Kirill Stoianov

1 answer 1

Try this:

 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myImageView.getLayoutParams(); params.width += 100; params.height += 100; myImageView.setLayoutParams(params); 
  • Your answer completely answers my question. Tell me, what was wrong in my code? Visually, they are almost the same, in my opinion. - Alexander Tkachenko
  • @AlexanderTkachenko, in fact, I don’t know exactly, but I think it is somehow connected with the fact that you in your code assigned new parameters to the view, and did not change the current ones. Plus, not always getWidth/Height work as you would expect. Those. it is better not to use them at all, but to take the dimensions from the parameters - YuriySPb