显示大于设备屏幕的图像

eya*_*yal 6 android scroll resize image android-imageview

我希望在不调整图像大小的情况下显示尺寸大于设备屏幕的图像.它必须以屏幕为中心.我怎样才能做到这一点?

Sun*_*hoo 6

使用带有图像视图的scrollview并设置该滚动视图的高度

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    <ImageView
        android:id="@+id/accountIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

  • 这对我来说非常有用!唯一的问题是 ImageView 在执行此操作后没有居中,因此我只需将 `layout_gravity="center"` 添加到 ImageView 即可。另请注意,在现代 Android 中, [fill_parent](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT) 已弃用,可以安全地用 [match_parent](https: //developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT)在所有情况下(因为它们都做完全相同的事情)。 (2认同)

Del*_*ity 5

我注意到我需要使用普通(垂直)和水平 ScrollView 才能双向滚动。如果还有其他方法,请告诉我。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView" >
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/horizontalScrollView">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView3"
            android:src="@drawable/big_map"/>
        </HorizontalScrollView>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

它从图像的左上角开始显示。如果我尝试使用 android:layout_gravity="center" 那么我会在右侧或底部看到白色部分。所以居中对我来说不起作用。

选项2:使用WebView控件,并在onCreate时使用图像加载它。