Android ImageView 导致底部出现空白

Android ImageView causing whitespace at the bottom

我下面的代码导致图像底部出现空白。我想让图像覆盖整个屏幕,但不知何故。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

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

    <ImageView
        android:src="@drawable/ohm"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"/>

    <ImageView
        android:id="@+id/logo"
        android:src="@drawable/test2"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"/>

    <ImageView
        android:id="@+id/night"
        android:src="@drawable/night"
        android:layout_width="340dp"
        android:layout_height="250dp"
        android:layout_below="@id/logo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"/>

    <EditText
        android:id="@+id/username"
        android:layout_width="340dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/night"
        android:layout_marginTop="20dp"
        android:alpha="0.2"
        android:background="@drawable/rounded_edittext_states"
        android:textColor="#D69E29"
        android:textStyle="bold"
        android:paddingLeft="15dp"
        android:hint="USERNAME"
        android:textColorHint="#D69E29"/>

    <EditText
        android:id="@+id/password"
        android:layout_width="340dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/username"
        android:layout_marginTop="10dp"
        android:alpha="0.2"
        android:background="@drawable/rounded_edittext_states"
        android:textColor="#D69E29"
        android:textStyle="bold"
        android:paddingLeft="15dp"
        android:hint="PASSWORD"
        android:textColorHint="#D69E29"/>

</RelativeLayout>
</ScrollView>

我试过换成不同的 scaleType 但还是一样。然后,如果我将 adjustViewBounds 更改为 false,图像的高度将变为两倍。

下图是我面临的 2 个问题。

http://i.imgur.com/BOM5Cfe.png http://i.imgur.com/Fe5WMoQ.png

我以前遇到过这个问题,我的解决办法是使用与屏幕width:height比例相同的图像。

我找到了这个问题的解决方案。我创建一个布局并将 ScrollView 放入其中,然后在 ScrollView 中创建另一个布局。我不确定这是好事还是坏事,但目前看来这是一个解决方案。将需要一些专家查看解决方案。

<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="match_parent"
tools:context=".MainActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ohm">

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

</ScrollView>
</LinearLayout>