简体   繁体   English

如何使图像可滚动? [Android平台]

[英]How can I make my image scrollable? [Android Platform]

I have an image that takes up a lot more space than the android screen. 我的图片占用的空间比Android屏幕大得多。 I want the image to be presented full size and the user can move in any direction. 我希望以全尺寸显示图像,并且用户可以向任何方向移动。 Like a map. 就像一张地图。

Any suggestions? 有什么建议么?

You can use a webview which gives this to you for free. 您可以使用一个免费的网络视图。 I'm not sure why but when I tried using the loadData method it didn't work, but using loadDataWithBaseURL with a null URL did. 我不知道为什么,但是当我尝试使用loadData方法时,它不起作用,但是使用具有空URL的loadDataWithBaseURL却起作用了。

With a webview your image can even be embedded in HTML. 使用网络视图,您的图像甚至可以嵌入HTML。 In the example below yourContent is simply a string. 在下面的示例中, yourContent只是一个字符串。

Eg 例如

yourView.loadDataWithBaseURL(null, yourContent, "text/html", "UTF-8", null);

这是我看到的教程,该教程做了您所描述的内容http://www.anddev.org/scrolling_a_picture_horizo​​ntally_and_vertically-t3245.html

You can put your image in an ImageView and wrap it using a ScrollView and a HorizontalScrollView like below. 您可以将图像放在ImageView中 ,然后使用ScrollViewHorizo​​ntalScrollView将其包装,如下所示。

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

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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/yourImage"/>

    </ScrollView>

</HorizontalScrollView>

So you can scroll it horizontally and vertically like a map. 因此,您可以像地图一样水平和垂直地滚动它。

尝试将滚动条与图像放置到xml布局中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM