How do you setLayoutParams() for an ImageView?

前端 未结 4 1637
梦谈多话
梦谈多话 2020-11-27 15:53

I want to set the LayoutParams for an ImageView but cant seem to find out the proper way to do it.

I can only find documentation in the API

4条回答
  •  星月不相逢
    2020-11-27 16:17

    Old thread but I had the same problem now. If anyone encounters this he'll probably find this answer:

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
    yourImageView.setLayoutParams(layoutParams);
    

    This will work only if you add the ImageView as a subView to a LinearLayout. If you add it to a RelativeLayout you will need to call:

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(30, 30);
    yourImageView.setLayoutParams(layoutParams);
    

提交回复
热议问题