【问题标题】:Displaying an image larger than the device's screen显示大于设备屏幕的图像
【发布时间】:2011-09-20 23:38:42
【问题描述】:

我想在不调整图像大小的情况下显示比设备屏幕更大的图像。它必须在屏幕上居中。我该怎么做?

【问题讨论】:

    标签: android image resize scroll android-imageview


    【解决方案1】:

    将滚动视图与图像视图一起使用并设置该滚动视图的高度

    示例

    <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>
    

    【讨论】:

    • 这对我很有用!唯一的问题是 ImageView 在这样做之后没有居中,所以我只需要在 ImageView 中添加layout_gravity="center"。另请注意,在现代 Android 中,fill_parent 已被弃用,并且在所有情况下都可以安全地替换为 match_parent(因为它们的作用完全相同)。
    【解决方案2】:

    我注意到我需要使用正常(垂直)和水平 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>
    

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

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

    【讨论】:

      【解决方案3】:

      从 View 派生,覆盖 onDraw 并在屏幕上绘制。

      【讨论】:

        【解决方案4】:

        您也可以使用框架布局。布局可以比屏幕大

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-09-09
          • 1970-01-01
          • 2021-06-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多