MapView之上添加浮动按钮

问题描述:在地图上添加一个按钮,可以响应点击。但是按钮时固定的,地图拖动时,按钮不能动。如下图所示: 

   刚开始接触地图开发时,也曾经在这个问题上纠结过。刚刚学会了在地图上添加各种图层,无论是在地图上画大头针也好,绘制路线也好,都是使用图层来处理。

   于是落入了一种思维的定式,那就是误以为在地图上添加任何标记,只能通过图层。

   其实很简单,MapView也是一种控件,我们只要使用相对布局方式,就能将按钮添加到地图之上来显示。

   布局文件如下所示:

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

    <com.mapabc.mapapi.MapView
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="@string/maps_api_key"
        android:clickable="true" />

    <Button
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Map"
        android:layout_marginRight="100dp"
        />
</RelativeLayout>
findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
    
    public void onClick(View v) {
     map.getController().animateTo(point);
     
    }
   });
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值