Search code examples
androidimageviewscale

Actual view's height is not fitted to proper content


I have an ImageView, it shows an image from resource. ImageView's widht is fixed (60dp). Height is set as wrap_content. The image is resized to fit to this width (saving aspect ration - this is perfect)

The problem is that android sets actual height to the image's heights before resizing. But I want this image to have exactly 60dp in width and height should be equal to image's height after resizing.

Here is layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView  
        android:layout_width="60dp" 
        android:layout_height="wrap_content" 
        android:src="@drawable/sample"
        android:background="#F0F0"/>
</LinearLayout>

enter image description here


Solution

  • try android:adjustViewBounds="true"