Set image height as software matching

I need to set the height of the imageview as matchparent programmatically. If it's a fixed height, I know how to set it.

but how can I set it as matchparent?

EDIT:

Actually the height of the parent layout is dynamic.so I need to make the height of the image as the height of the parent.

+43
android height imageview
Apr 25 2018-12-12T00:
source share
6 answers

initiate LayoutParams.

assign the parent width and height and pass it to the setLayoutParams method of the image

+4
Apr 25 2018-12-12T00:
source share
imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
+140
Apr 25 2018-12-12T00:
source share
 imageView.getLayoutParams().height= ViewGroup.LayoutParams.MATCH_PARENT; 
+22
May 24 '16 at 10:17
source share
 imageView.setLayoutParams (new ViewGroup.MarginLayoutParams (width, ViewGroup.LayoutParams.MATCH_PARENT)); 

The type of layout options depends on the parent view group. If you make a mistake, this will throw an exception.

+12
Apr 25 2018-12-12T00:
source share

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

+1
Apr 25 '12 at 6:45
source share

You can try this incase, which you would like to map to the parent. Sizing - width and height in

 web = new WebView(this); web.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 
+1
Apr 09 '16 at 5:38 on
source share



All Articles