在设备屏幕之外显示一个更大的图像

7

我想在设备屏幕上显示比图片尺寸更大的图像,而不改变图片大小。同时需要将其居中显示在屏幕上。如何实现?

4个回答

7

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

示例

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

2
这对我非常有效!唯一的问题是在这样做后,ImageView没有居中,所以我只需要在ImageView中添加layout_gravity="center"。还要注意,在现代Android中,fill_parent已被弃用,并且可以在所有情况下安全地替换为match_parent(因为它们都执行完全相同的操作)。 - Charles Madere

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>

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

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


0

您还可以使用帧布局进行工作。布局可以比屏幕更大。


0
继承View类,重写onDraw方法并在屏幕上绘制它。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接