set height of imageview as matchparent programmati

2020-05-14 04:34发布

I need to set the height of an imageview as matchparent programatically.if it is a fixed height i know how to set.

but how can i set it as matchparent?

EDIT:

actually height of the parent layout is dynamic.so i need to make the height of the imageview as the height of parent.

8条回答
够拽才男人
2楼-- · 2020-05-14 05:14

You can use the MATCH_PARENT constant or its numeric value -1.

查看更多
Luminary・发光体
3楼-- · 2020-05-14 05:18
imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
查看更多
我命由我不由天
4楼-- · 2020-05-14 05:20

initiate LayoutParams .

assign the parent's width and height and pass it to setLayoutParams method of the imageview

查看更多
放荡不羁爱自由
5楼-- · 2020-05-14 05:23

I had same issue. Resolved by firstly setting :

imageView.setMinHeight(0);
imageView.setMinimumHeight(0);

And then :

imageView.getLayoutParams().height= ViewGroup.LayoutParams.MATCH_PARENT;

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.

查看更多
Fickle 薄情
6楼-- · 2020-05-14 05:23
imageView.getLayoutParams().height= ViewGroup.LayoutParams.MATCH_PARENT;
查看更多
劫难
7楼-- · 2020-05-14 05:26

You can try this incase you would like to match parent. The dimensions arrangement is width and height inorder

web = new WebView(this);
        web.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
查看更多
登录 后发表回答