Android: Set ImageView layout_height programmatically

Viewed 44015

I have an ImageView in my main.xml file:

<ImageView
            android:id="@+id/pageImage"
            android:layout_width="270dp"
            android:layout_height="45dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="15dp"
            android:scaleType="fitXY"
            android:src="@drawable/pageimage" />

What I only need to do is to set the the layout_height programmatically to another value.

Additionally, I need to set the value in dp. So it is currently 45dp, I'd like to change it to another value in my main activity.

I tried to figure out how to do this using LayoutParams, but I couldn't succeed.

Thanks.

2 Answers
Related