Android 如何缩放和滚动动态创建的位图

发布于 2024-11-18 07:02:31 字数 724 浏览 8 评论 0原文

在我的应用程序中,我使用以下代码来保存从服务器下载的地图。

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情定在深秋 2024-11-25 07:02:31

Sephiroto 基于 Gallery 应用程序代码制作了一个非常简单的 ImageViewTouch : http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

我在一个项目中使用它,它工作得很好,捏合缩放以及您可能想要的一切。默认情况下,当您为其设置图像时,图像将缩小以适合屏幕。

编辑:如果您想防止自动调整图像大小,可以将 ImageViewTouchBase.getProperBaseMatrix 方法更改为以下内容:

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);
}

这应该使图像居中而不调整其大小。

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 :

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文