在 Android 中将 imageView 中的 space 翻倍

Image taking Double the space in imageView in Android

我已经在 Imageview 中放了一张图片,但它占用了 space 的两倍。图像和它下面的文本视图之间有很大的差距。我如何设置图像以使用图像的高度?

我的布局如下:

<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"

    android:gravity="center" android:padding="5dp" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/babyfa"

        android:scaleType="fitStart"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"


        android:text="@string/whatis"
    />

我附上了图像,红线表示 imageview 正在拍摄的额外 space。请指教。Image

这可能是由 android:scaletype="fitStart" 引起的。尝试从您的 XML 中删除它。请参阅 this helpful guide 了解不同 scaletype 属性的效果(fitStart 在底部)。

编辑:也尝试设置 android:adjustViewBounds="true"。这将有希望强制 ImageView 保持图像的纵横比。