Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用pin按钮(ImageButtons)实现静态地图的简单缩放?_Android_Android Layout_Android Widget_Scrollview_Imagebutton - Fatal编程技术网

Android 如何使用pin按钮(ImageButtons)实现静态地图的简单缩放?

Android 如何使用pin按钮(ImageButtons)实现静态地图的简单缩放?,android,android-layout,android-widget,scrollview,imagebutton,Android,Android Layout,Android Widget,Scrollview,Imagebutton,我的应用程序中的一个活动需要显示一个静态地图(一个本地png文件),其中包含预先确定的地图pin位置。静态映射的大小是480 px x 904 px,我用scrollview实现了它,这样我就可以上下滚动查看映射及其各个引脚位置。pin被实现为imagebutton(通过编程而不是使用xml创建),单击它们将启动其他相应的新活动。我想知道如何实现一个简单的缩放功能,用户可以双击地图上的任何地方,它将放大(例如2倍)到点击区域(因此点击区域周围的pin图像按钮也将被缩放)。不会有挤压或多点触摸操作

我的应用程序中的一个活动需要显示一个静态地图(一个本地png文件),其中包含预先确定的地图pin位置。静态映射的大小是480 px x 904 px,我用scrollview实现了它,这样我就可以上下滚动查看映射及其各个引脚位置。pin被实现为imagebutton(通过编程而不是使用xml创建),单击它们将启动其他相应的新活动。我想知道如何实现一个简单的缩放功能,用户可以双击地图上的任何地方,它将放大(例如2倍)到点击区域(因此点击区域周围的pin图像按钮也将被缩放)。不会有挤压或多点触摸操作,所以只需简单地双击以放大被点击区域,然后再次双击以缩小。顺便说一句,我的活动是在横向模式,所以不必担心切换方向。有什么建议吗

这是我的xml文件中用于活动的一部分

<?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类的一部分:

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

         ...
    }
    ...        
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.result\u映射);
setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向);
mapLocArray=getMapCoordinates();
RelativeLayout rl=(RelativeLayout)findViewById(R.id.rlayoutResultMap);
//循环浏览并创建地图位置按钮
int x,y;
对于(inti=1;i为什么不做y

<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" />

我希望我能正确理解你的问题。

Thaks接受这个建议。因为我发布了这个问题,我找到了一种实现双击手势侦听器的方法,所以我不需要像你建议的那样定义zoombutton。但是,我尝试了类似于你建议的方法,但返回的image变量为null。我通过:
Bitmap image=BitmapFactory.decodeResource(getResources(),R.id.imgResultMap)
上面列出的xml中定义了imgResultMap。知道为什么吗?另外,由于我的地图还包含用于地图引脚的ImageButton,我想在缩放地图时也缩放它们。可以这样做吗?谢谢。问题解决了。原来我应该使用R.drawable.imgResultMap,它工作得很好。但是,有没有办法执行s在RelativeLayout上进行了类似的整体调整,特别是因为我有ImageView和多个ImageButtons?还有,我如何告诉它将最终图像定位在双击的位置?我最终对布局中的每个元素进行了调整。虽然不是最漂亮的,但效果很好。如果知道如何定位缩放后的ima,我会很高兴GE,让双击区域在屏幕中间。无论如何,都会让这个答案被接受。谢谢Phil!
int zoom = 2;
Bitmap i = Bitmap.createScaledBitmap(image, image.getWidth() * zoom, image.getHeight() * zoom, false);