Android 实际视图';s的高度不适合适当的内容

Android 实际视图';s的高度不适合适当的内容,android,imageview,scale,Android,Imageview,Scale,我有一个ImageView,它显示了一个来自资源的图像。 ImageView的宽度是固定的(60dp)。高度设置为包裹内容。 将图像调整大小以适应此宽度(保存纵横比-这很完美) 问题是android在调整大小之前将实际高度设置为图像的高度。但我希望这张图片的宽度和高度正好是60dp,调整大小后应该等于图片的高度 这里是布局图 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sc

我有一个ImageView,它显示了一个来自资源的图像。 ImageView的宽度是固定的(60dp)。高度设置为包裹内容。 将图像调整大小以适应此宽度(保存纵横比-这很完美)

问题是android在调整大小之前将实际高度设置为图像的高度。但我希望这张图片的宽度和高度正好是60dp,调整大小后应该等于图片的高度

这里是布局图

<?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>


解决方案非常简单,我刚刚为标签添加了atribute
android:adjustViewBounds=“true”

试试android:adjustViewBounds=“true”

有两种解决方案

<?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="60dip" 
        android:layout_height="wrap_content" 

        android:background="@drawable/thumb"
        android:adjustViewBounds="true"/>
</LinearLayout>