如何解决 Android 中 IMAGEVIEW 的错误高度百分比

How to solve wrong HEIGHT of IMAGEVIEW in percentage in Android

我尝试了一些想法来实现以下目标:

对于描述:我想要一个 header 和一个文本视图,它环绕在 howl 页面之上,在这个 header 下面我想显示三个图像并排显示。它应该像一个图片库。我想复制这个布局。

但我的问题是,我的 ImageView 的高度太高,而且调整大小的图像和标题之间有一段距离。见图

左边是我想要的,右边是我得到的...

这是我的布局代码:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:layout_weight="1">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:textStyle="bold"
            android:text="titel"
            android:id="@+id/titel"
            android:gravity="center"
            android:padding="3dp"
            android:textSize="18sp"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/titel">

        <ImageView
            android:layout_width="0dp"
            android:layout_weight="0.208"
            android:layout_height="match_parent"
            android:id="@+id/image1"
            android:src="@drawable/1"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_weight="0.389"
            android:layout_height="match_parent"
            android:id="@+id/image2"
            android:src="@drawable/2"/>

        <ImageView
            android:layout_width="0dp"
            android:layout_weight="0.403"
            android:layout_height="match_parent"
            android:id="@+id/image3"
            android:src="@drawable/3"/>

        </LinearLayout>

    </RelativeLayout>

</ScrollView>

我最好的猜测是因为您的 ImageView 以适合视图中心的方式缩放图像,并在视图的顶部和底部留空 space。尝试将 android:adjustViewBounds="true" 添加到 xml 中的 ImageView

附带说明一下,在调试视图层次结构时,转到 Android Device Monitor、select 右侧的设备并单击 Dump View Hierarchy for UI Automator 几乎总是有帮助的。通过将鼠标悬停在不同的视图元素上,您可以轻松找出哪个视图占用了额外的 space。