Kotlin Android – Set Specific Height for ImageView

To set specific height for ImageView in Kotlin Android, set android:layout_height attribute of ImageView in layout file with required height.

The following code snippet demonstrates to set specific height for ImageView.


Example Android Application

Let us create an Android Application with ImageView.

Refer Kotlin Android – ImageView Example to create an Android Application with just an ImageView in LinearLayout, and follow these steps.

Set ImageView Height

Open activity_layout.xml file and switch to design mode.

By default, the layout height of the ImageView is set to wrap the content.


We can change this value to required height, say 300dp. Click on the wrap_content value for layout_height attribute and set the height to 300dp.

As we can observe in the blueprint, the height of ImageView is changed.

Change ImageView Height in XML Code

If not in Design mode, we can also change the height in Code. Change the value of layout_height for ImageView in activity_main.xml file as shown in the following.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        app:srcCompat="@drawable/sample_image" />


Run the Android Application

Now, let us run the Android Application, and see if the height of the ImageView is set to the specified value.

Android ImageView - Set Specific Height


In this Kotlin Android Tutorial, we learned how to set specific height for ImageView in Android Application.