Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proportionally size an imageview in Android

Suppose you have this

<ImageView
        android:id="@+id/mainImageView"
        android:layout_width="match_parent"
        android:background="@drawable/mylogo_250px60px"
/>

I would like to define height so it scales accordingly to width. So if Android decides to scale logo to be shown in width, height should increase as well.

Is it also possible to define something, so when the phone is tilted from vertical to horizontal, the logo will scale correctly?

(Basically, the logo is above a listview on the main activity)

I have also tried using this, but no luck (the height appears much to low compared to width. Image is not resized/scaled in height)

<ImageView
        android:id="@+id/mainImageView"
        android:layout_width="match_parent"
        android:background="@drawable/mylogo_250px60px"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:adjustViewBounds="true"                                       
    />

If I design it in Eclipse/ADT gui tool logo gets 76dp and looks good on my two test phones. However, I think it should be possible to simply scale image propertionally?

"fixed height" has correct rato to width (vertical view, not when phone is tilted) enter image description here

"auto height" appears wrong ratio wise compared to width: enter image description here

like image 345
Tom Avatar asked Oct 23 '25 08:10

Tom


1 Answers

Change your imageview code as below

 <ImageView
        android:id="@+id/mainImageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/mylogo_250px60px"
        android:scaleType="fitEnd"
        android:adjustViewBounds="true"
    />
like image 166
Sankar V Avatar answered Oct 25 '25 21:10

Sankar V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!