Android ImageView 左右 space

Android ImageView with space left and right

我有一个 HorizontalScrollView 和一个 RelativeLayout 和一个 ImageView。我的目标是让 ImageView 以全高但溢出宽度显示我的图像,以便您可以水平滚动图像。

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_indoor_tour"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="#ff0000">

        <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scene"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:background="#ffff00" />
    </RelativeLayout>
</HorizontalScrollView>

它一般都能正常工作,但增加了一些左右间距,这是 ImageView 的一部分。

见截图。

间距从何而来?如何去掉这个间距?

尝试在 imageView 上添加此属性:

android:scaleType="fitXY"

android:layout_width="match_parent"

相对布局和 ImageView

以下在我的情况下工作正常。

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_indoor_tour"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000">

        <ImageView
            android:id="@+id/scene"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:background="#ffff00" />
    </RelativeLayout>
</HorizontalScrollView>

我认为图像本身有左右填充。否则它应该可以正常工作。