如何实现与销按钮(ImageButtons)静态地图简单的缩放? [英] How to implement simple zoom for static map with pin buttons (ImageButtons)?

查看:266
本文介绍了如何实现与销按钮(ImageButtons)静态地图简单的缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个我的应用程序的活动需要显示静态地图(本地PNG文件)pre-确定的地图引脚位置。静态地图为480像素点¯x904在尺寸像素,和我有一个滚动视图来实现它,这样我可以上下滚动查看地图及其各引脚位置。引脚被实现为ImageButtons(程序创建的,而不是使用XML),并单击它们将推出其他相应的新的活动。我想知道如何实现一个简单的缩放功能,用户可以双击任意位置在地图上,它会在(2个为实例)放大到挖掘区域(等周围的挖掘区域销ImageButtons会被放大也)。将有没有允许或捏多点触控操作,以便只是简单的双攻放大到挖掘区域,双击再次缩小。顺便说一句,我的活动是在横向模式下只所以没有必要担心切换方向。任何建议?

One of the activities in my app needs to display a static map (a local png file) with pre-determined map pin locations. The static map is 480 px x 904 px in size, and I have implemented it with a scrollview so that I can scroll up and down to view the map and its various pin locations. The pins are implemented as ImageButtons (created programmatically instead of using xml), and clicking them will launch other corresponding new activities. I would like to know how to implement a simple zoom feature where the user can double-tap anywhere on the map and it will zoom in (2x for instance) to the tapped area (and so the pin ImageButtons around the tapped area will be zoomed also). There will be no pinching or multi-touch actions allowed so just simple double tapping to zoom into the tapped area and double tap again to zoom out. BTW, my activity is in landscape mode only so no need to worry about switching orientation. Any advise?

下面是该活动的我的XML文件的一部分

Here is a portion of my xml file for the activity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rlayoutResultMap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="0dp" >

    <ScrollView
        android:id="@+id/scrollResultMap"
        android:fillViewport="true" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:scrollbars="none" >

        <RelativeLayout
            android:id="@+id/rlayoutScrollMap"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:id="@+id/imgResultMap"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_alignParentTop="true"
                android:src="@drawable/map_base"/>

        </RelativeLayout>
    </ScrollView>
    ...
</RelativeLayout>

这是我的Java类的部分内容:

And here is a portion of my java class:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result_map);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mapLocArray = getMapCoordinates();

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.rlayoutResultMap);

    // Loop through and create the map location buttons
    int x, y;
    for (int i=1; i<=maxMapLoc; i++ ) {
        mapLocation = i;
        ImageButton btnMapLoc = new ImageButton(ResultMapActivity.this);
        RelativeLayout.LayoutParams vp = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        x = mapLocArray[i-1].getX();
        y = mapLocArray[i-1].getY();
        vp.setMargins(x,y,0,0);         
        btnMapLoc.setLayoutParams(vp);
        btnMapLoc.setBackgroundColor(Color.TRANSPARENT);
        btnMapLoc.requestLayout();

        String imgNameNormal = "map_loc_" + mapLocation + "_normal"; 
        int idNormal = getResources().getIdentifier(imgNameNormal,"drawable",getPackageName());
        btnMapLoc.setImageResource(idNormal);

        rl.addView(btnMapLoc, vp);

         ...
    }
    ...        
}

先谢谢了。

推荐答案

为什么你不做是

<ZoomButton
android:id="@+id/zoomButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageButton1"
android:layout_centerHorizontal="true"
android:src="@android:drawable/btn_plus" />

,以便用户知道该怎么做。
当您使用2 *标签让你必须开始AFER第​​一选项卡中的定时任务并在用户preS再次第二个选项卡,在你在定时器实现***毫秒任务你必须放大。

so that the user know what to do. When you make it with 2*tab you have to start afer first tab a Timer Task and when the user pres again second tab, in ***ms that you have to implement in the Timer Task you have to zoom.

和得到一个放大的图像可以使用

And to get a zoomed Image you can use

int zoom = 2;
Bitmap i = Bitmap.createScaledBitmap(image, image.getWidth() * zoom, image.getHeight() * zoom, false);

我希望我理解你的问题的权利。

I hope I understand you question right.

这篇关于如何实现与销按钮(ImageButtons)静态地图简单的缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆