拉伸ImageView以填充水平滚动视图内部的屏幕高度

Jos*_*h.M 1 android stretching horizontalscrollview imageview

我已经阅读了所有关于支持不同屏幕外观的文章。并且,我提供了要显示的图像的适当变体到适当的文件夹。但是,我为之困惑。ImageView的文档说,将android:layout_width和android:layout_height设置为“ fill_parent” /“ match_parent”将导致图像拉伸以填满整个屏幕。(这似乎是必要的,因为并非所有的屏幕密度都提供相同的尺寸/像素数的屏幕,并且我不希望那些多余的像素导致在屏幕底部出现填充)这似乎在其他时间都有效,但不起作用对我来说,当ImageView放置在Horizo​​ntalscrollview内并且图像的宽度大于屏幕的宽度时。

我的代码如下:(该活动在清单中设置为横向)

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hscrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:fadingEdge="none"
    android:scrollbars="none"
    android:overScrollMode="never" >

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:fadingEdge="none"
    android:scrollbars="none"
    android:overScrollMode="never" >

<ImageView
    android:id="@+id/MapImageView"
    android:src="@drawable/map"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" />
</RelativeLayout>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)

编辑:我用:background替换了:src无效。

这是我在平板电脑等设备上获得的效果。理想情况下,我希望图像在具有典型480x800分辨率或类似分辨率的手机上像下面一样填充整个屏幕。

这是我在平板电脑等设备上获得的效果。 理想情况下,我希望图像能充满整个屏幕,就像在具有典型480x800分辨率或类似分辨率的手机上一样。

Man*_*ika 6

尝试android:scaleType="fitXY"在您的中使用ImageView