Android的我怎么缩放和滚动它是动态创建的位图 [英] Android how do I zoom and scroll a bitmap which is created on the fly
问题描述
在我的应用程序中,我使用下面的code,用于保存从服务器下载地图。
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>
目前,我可以滚动图像上下只。 我需要将图像滚动到各个方向的能力,同时也放大和缩小它。 如何可以做到? 谢谢, 的Eyal。
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.
推荐答案
有一个非常简单的ImageViewTouch的Sephiroto国产基础上Gallery应用程序code:的 http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/
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.
编辑:如果你想prevent自动图像调整大小,您可以更改ImageViewTouchBase.getProperBaseMatrix方法如下:
edit : if you want to prevent the automatic image resize, you can change the ImageViewTouchBase.getProperBaseMatrix method to the following :
protected void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) {
float viewWidth = getWidth();
float viewHeight = getHeight();
float w = bitmap.getWidth();
float h = bitmap.getHeight();
matrix.reset();
matrix.postConcat(bitmap.getRotateMatrix());
matrix.postTranslate((viewWidth - w) / 2, (viewHeight - h) / 2);
}
这应该图像居中而不调整其大小。
This should center the image without resizing it.
这篇关于Android的我怎么缩放和滚动它是动态创建的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!