and*_*irl 72 height android imageview
我需要以编程方式将imageview的高度设置为matchparent.如果它是一个固定的高度,我知道如何设置.
但我怎么能把它设置为matchparent?
编辑:
实际上父布局的高度是动态的.所以我需要将imageview的高度设为父级的高度.
C. *_*ung 222
imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
Run Code Online (Sandbox Code Playgroud)
Luk*_*son 49
imageView.getLayoutParams().height= ViewGroup.LayoutParams.MATCH_PARENT;
Run Code Online (Sandbox Code Playgroud)
xan*_*ndy 15
imageView.setLayoutParams
(new ViewGroup.MarginLayoutParams
(width, ViewGroup.LayoutParams.MATCH_PARENT));
Run Code Online (Sandbox Code Playgroud)
布局参数的类型取决于父视图组.如果你选错了它会导致异常.
Muh*_*s M 12
对于 Kotlin 用户
val params = mImageView?.layoutParams as FrameLayout.LayoutParams
params.width = FrameLayout.LayoutParams.MATCH_PARENT
params.height = FrameLayout.LayoutParams.MATCH_PARENT
mImageView?.layoutParams = params
Run Code Online (Sandbox Code Playgroud)
在这里我使用,FrameLayout.LayoutParams因为我的 views( ImageView) 父母是FrameLayout
I had same issue. Resolved by firstly setting :
imageView.setMinHeight(0);
imageView.setMinimumHeight(0);
Run Code Online (Sandbox Code Playgroud)
And then :
imageView.getLayoutParams().height= ViewGroup.LayoutParams.MATCH_PARENT;
Run Code Online (Sandbox Code Playgroud)
setMinHeight is defined by ImageView, while setMinimumHeight is defined by View. According to the docs, the greater of the two values is used, so both must be set.
luc*_*uke -19
启动 LayoutParams 。
分配父级的宽度和高度并将其传递给 imageview 的 setLayoutParams 方法