Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set height of imageview as matchparent programmatically

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.

like image 619
andro-girl Avatar asked Apr 25 '12 06:04

andro-girl


People also ask

How set Imageview width and height dynamically in Android?

If you want to just fit the image in image view you can use" wrap content" in height and width property with scale-type but if you want to set manually you have to use LayoutParams. Layoutparams is efficient for setting the layout height and width programmatically.

How do I change the image size on Kotlin?

This example demonstrates how to resize Image in an Android App using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
like image 180
C. Leung Avatar answered Oct 09 '22 08:10

C. Leung


imageView.getLayoutParams().height= ViewGroup.LayoutParams.MATCH_PARENT; 
like image 40
Luke Allison Avatar answered Oct 09 '22 09:10

Luke Allison