你怎么setLayoutParams()为ImageView的? [英] How do you setLayoutParams() for an ImageView?
问题描述
我想设置的LayoutParams
为的ImageView
,但不能似乎找到了正确的方法来做到这一点
I want to set the LayoutParams
for an ImageView
but cant seem to find out the proper way to do it.
我只能找到各种 ViewGroups
中的API文档,而不是一个的ImageView
。然而,的ImageView
好像有这个功能。
I can only find documentation in the API for the various ViewGroups
, but not an ImageView
. Yet the ImageView
seems to have this functionality.
这code不工作...
This code doesn't work...
myImageView.setLayoutParams(new ImageView.LayoutParams(30,30));
我该怎么办呢?
How do I do it?
推荐答案
您需要设置的ViewGroup ImageView的是坐在的的LayoutParams。例如,如果你的ImageView的是里面的LinearLayout,然后创建一个
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.
这篇关于你怎么setLayoutParams()为ImageView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!