How do you setLayoutParams() for an ImageView?

前端 未结 4 1638
梦谈多话
梦谈多话 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:41

    You need to set the LayoutParams of the ViewGroup the ImageView is sitting in. For example if your ImageView is inside a LinearLayout, then you create a

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

    This is because it's the parent of the View that needs to know what size to allocate to the View.

提交回复
热议问题