我有一个 ImageView,它显示来自资源的图像。 ImageView 的宽度是固定的 (60dp)。高度设置为 wrap_content。 调整图像大小以适合此宽度(节省宽高比 - 这很完美)
问题是 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>
最佳答案
试试 android:adjustViewBounds="true"
关于android - 实际 View 的高度不适合适当的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6198997/