How do you setLayoutParams() for an ImageView?

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

    If you're changing the layout of an existing ImageView, you should be able to simply get the current LayoutParams, change the width/height, and set it back:

    android.view.ViewGroup.LayoutParams layoutParams = myImageView.getLayoutParams();
    layoutParams.width = 30;
    layoutParams.height = 30;
    myImageView.setLayoutParams(layoutParams);
    

    I don't know if that's your goal, but if it is, this is probably the easiest solution.

提交回复
热议问题