android - android map v2中的自定义信息窗口

标签 android google-maps-api-2

我正在尝试在android map v2中开发一个自定义信息窗口。我想知道如何从信息窗口中删除白色背景以及如何将圆半径外的背景设置为透明黑色enter image description here

这是我的自定义信息窗口的 xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/dp"
    android:orientation="vertical">



</LinearLayout>

这是我制作自定义信息窗口的代码

 getMap().getMap().setInfoWindowAdapter(new InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker arg0) {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public View getInfoContents(Marker arg0) {
                    // TODO Auto-generated method stub
                    // Getting view from the layout file info_window_layout
                    View v = getLayoutInflater().inflate(R.layout.windowlayout,
                            null);

                    return v;
                }
            });
private SupportMapFragment getMap() {
        return ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map));
    }

这是我的标记点击

@Override
    public void onMapClick(LatLng point) {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), point.toString(),
                Toast.LENGTH_SHORT).show();
        getMap().getMap().animateCamera(CameraUpdateFactory.newLatLng(point));
        CameraUpdate zoom = CameraUpdateFactory.zoomTo(8);

        getMap().getMap().moveCamera(CameraUpdateFactory.newLatLng(point));
        getMap().getMap().animateCamera(zoom);
        Marker marker;
        getMap().getMap().clear();
        marker = getMap().getMap().addMarker(
                new MarkerOptions()
                        .draggable(true)
                        .position(point)
                        .title("Pick Up")
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.marker)));

        // marker.setPosition(point);
        marker.showInfoWindow();
        rl.setVisibility(View.VISIBLE);
    }

这是我的 map 布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/data"
        android:layout_alignParentTop="true" >

        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.muratonnet.map.TouchableSupportMapFragment" />

        <RelativeLayout
            android:id="@+id/rl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/circle"
            android:layout_gravity="center"
            android:visibility="gone" >
        </RelativeLayout>
    </FrameLayout>

    <LinearLayout
        android:id="@+id/data"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <include layout="@layout/data_table" />
    </LinearLayout>

</RelativeLayout>

最佳答案

请在 getInfoWindow() 而不是 getInfoContents();

设置你的 infowindow View

通过这个你可以删除infoWindow的默认背景。

所以你必须像这样膨胀你的观点:

getMap().setInfoWindowAdapter(new InfoWindowAdapter() {

                @Override
                public View getInfoWindow(Marker arg0) {
                    // TODO Auto-generated method stub
                    // Getting view from the layout file info_window_layout
                    View v = getLayoutInflater().inflate(R.layout.windowlayout,
                            null);

                    return v;
                }

                @Override
                public View getInfoContents(Marker arg0) {
                    return null;
                }
            });
private SupportMapFragment getMap() {
        return ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map));
    }

关于android - android map v2中的自定义信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26230098/

相关文章:

Android map v2 缩放以显示所有标记

android - android中ffmpeg中的av_read_frame函数总是返回packet.stream_index为0

android - 您如何使字段成为 Android Saripaar 中不需要的电子邮件字段?

即使实现了可序列化,也会抛出 java.io.NotSerializedException

android - 如何在多段线路径上为 google map v2 标记设置动画?

google-maps - 如何检索显示城市或自治市边界的静态 map

java - Mapbox:无法在 gradle 中添加 LocationLayer 插件

android - 用户无法在手机上打开 android 应用程序,他们必须从 android 市场打开

php - Google Maps API Javascript API v2 返回 "sensor"问题

android - Google Maps android通过在 map 中移动标记来获取经纬度