显示高度为 'matchparent' 的图像并保持宽高比

Display an image with height 'matchparent' and also keep the aspectratio

我想在 Imageview 中以全高显示图像并保持图像的纵横比。要查看图像的其余部分,我想在该图像上水平滚动。请分享其背后的想法?

结合 adjustViewBound 和 scaleType="fitXY" 来实现您的目标。这将保持图像的纵横比。像这样:

<ImageView
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

ResolutioN 所述,adjustViewBounds 可以解决问题,但 fitXY 不是必需的。只需将 ImageView 包裹在 HorizontalScrollView

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:src="@drawable/image" />

</HorizontalScrollView>

希望此代码对您有所帮助:

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/horizontalScrollView"
    >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"/>

</HorizontalScrollView>