Android 如何缩放和滚动动态创建的位图
在我的应用程序中,我使用以下代码来保存从服务器下载的地图。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_weight="1.0">
<ImageView android:id="@+id/mapImageView"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:scaleType="center"/>
</ScrollView>
目前,我只能上下滚动图像。 我需要能够将图像滚动到各个方向并放大和缩小。 怎样才能做到呢? 谢谢, 埃亚尔。
In my application, i'm using the following code for holding a map which is downloaded from a server.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/scrollView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_weight="1.0">
<ImageView android:id="@+id/mapImageView"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:scaleType="center"/>
</ScrollView>
currently, i can scroll the image up and down only.
I need to have the ability to scroll the image to all directions and also to zoom it in and out.
How it can be done?
Thanks,
Eyal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Sephiroto 基于 Gallery 应用程序代码制作了一个非常简单的 ImageViewTouch : http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/
我在一个项目中使用它,它工作得很好,捏合缩放以及您可能想要的一切。默认情况下,当您为其设置图像时,图像将缩小以适合屏幕。
编辑:如果您想防止自动调整图像大小,可以将 ImageViewTouchBase.getProperBaseMatrix 方法更改为以下内容:
这应该使图像居中而不调整其大小。
There's a very simple ImageViewTouch that Sephiroto made based on the Gallery application code : http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/
I use it in a project and it works perfectly, with pinch-to-zoom and everything you might want. By default, when you set an image to it, the image will be scaled down to fit the screen.
edit : if you want to prevent the automatic image resize, you can change the ImageViewTouchBase.getProperBaseMatrix method to the following :
This should center the image without resizing it.