How do you change the size of ImageView?



  • There are several ImageView and Button on the fragment. In the Button click, ImageView is required to change the dimensions. The whole RelativeLayout.

    I'm trying to achieve the result by:

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

    In the Button click, ImageView's successfully increased. There are no results for repeat clicks, i.e. ImageView dimensions are no longer changing. Which way?



  • Try this:

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) myImageView.getLayoutParams();
    params.width += 100;
    params.height += 100;
    myImageView.setLayoutParams(params);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2