开发者

Android - How to copy setBuiltInZoomControls functionality

开发者 https://www.devze.com 2023-01-04 00:48 出处:网络
Here is my problem: When I click on the map view , the \"setBuiltInZoomControls\" method displays the zoom controls and then hides it. I want to copy that functionality so that when I click on the map

Here is my problem: When I click on the map view , the "setBuiltInZoomControls" method displays the zoom controls and then hides it. I want to copy that functionality so that when I click on the map view I want to display the map, satellite and traffic buttons, but my code doesn't work.

Can you help me on this? I have included my code below.

This is my xml code:

parent"
    android:layout_height="fill_parent"
    android:id="@+id/mapLayout"
    >

<com.google.android.maps.MapView
    android:id="@+id/mapview1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="0K5oQk-IVWGzfMbBkOhx5EDXDXhlBO1PJI8mLag" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="48px"
        android:background="#550000ff"
        android:padding="2px"
        android:id="@+id/mapBtnsControlls"
        android:visibility="invisible">

        <Button
            android:layout_width="wrap_content"
            android:id="@+id/btnMap"
            android:layout_height="wrap_content"
            android:text="Map"
            android:layout_marginLeft="53px"
            android:layout_marginRight="10px">
        </Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btnSatellite" 
            android:text="Satellite"
            android:layout_toRightOf="@+id/btnMap"
            android:layout_marginRight="10px">
        </Button>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btnTraffic"
            android:layout_toRightOf="@+id/btnSatellite"
            android:text="Traffic">
        </Button>
    </RelativeLayout>   
</RelativeLayout>

This is my java code:

MapView googleMap= (MapView) findViewById(R.id.mapview1);
RelativeLayout mapBtnsLayout = (RelativeLayout) findViewById(R.id.mapBtnsControlls);

googleMap.setClickable(true);
googleMap.setOnClickListener(new View.OnClickListener() {
   public void开发者_如何学编程 onClick(View v) {
      mapBtnsLayout.setVisibility(View.VISIBLE);  
   }
}); 


Instead of using setClickable() and setOnClickListener() on the MapView, try adding an Overlay subclass and overriding onTouchEvent() to show your controls.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号