6

我正在使用 InfoWindowAdapter 将自定义信息窗口添加到我的标记中。除了一件事外,一切都很好,我找不到为我的信息窗口设置圆边的方法

我正在使用 google mapV2。任何与此相关的代码片段都会非常有帮助

4

3 回答 3

13
 gMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) 
        {
            View vMapInfo = ((Activity) context).getLayoutInflater().inflate(R.layout.map_info_layout, null);
            return vMapInfo;
        }

        @Override
        public View getInfoContents(Marker arg0) 
        {
            //View v = getLayoutInflater().inflate(R.layout.map_info_layout, null);
            return null;            

        }
    });

map_info_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/bg_map_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
 >

<RelativeLayout
    android:layout_width="250dp"
    android:layout_height="45dp"
    android:background="@drawable/bg_map_info"
    android:paddingTop="0dp"
    android:paddingBottom="0dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
     >

    <TextView
        android:id="@+id/tvMapStoreName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="3dp"
        android:layout_marginTop="2dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_toLeftOf="@+id/ivMapGo"
        android:ellipsize="end"
        android:lines="1"
        android:text="test text test text test text test text "
        android:textColor="#ffffff"
        android:textSize="@dimen/txt_size_common"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/ivMapGo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/tvMapStoreDistance"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tvMapStoreName"
        android:layout_below="@+id/tvMapStoreName"
        android:lines="1"
        android:text="100 Miles"
        android:textColor="#FFFFFF"
        android:textSize="12dp"
        android:textStyle="normal" />

</RelativeLayout>



</LinearLayout>

以下是信息窗口背景的 XML。

bg_map_info.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item> 
    <shape android:shape="rectangle">
        <gradient android:angle="-90" android:startColor="#a0333333"
            android:endColor="#a0000000" />
        <corners 
            android:bottomLeftRadius="5dp"
            android:bottomRightRadius="5dp"
            android:topLeftRadius="5dp" 
            android:topRightRadius="5dp" />         

    </shape>
</item>
<item android:top="20dp"> 
    <shape android:shape="rectangle">
        <gradient android:angle="-90" android:startColor="#70000000"
            android:endColor="#70000000" />
        <corners 
            android:bottomLeftRadius="5dp"
            android:bottomRightRadius="5dp"
            android:topLeftRadius="5dp" 
            android:topRightRadius="5dp" />     </shape>
</item>
</layer-list>
于 2013-07-12T10:53:07.270 回答
0

如果将 .xml 文件扩展为方法 getInfoWindow(),它可以正常工作。此方法允许您提供将用于整个信息窗口的视图。

于 2021-04-16T13:11:09.677 回答
0

自定义信息窗口布局:-

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/btn_bg_white"
    android:orientation="vertical"
    android:padding="@dimen/_10dp_">

    <LinearLayout
        android:layout_width="224dp"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/info_window_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:fontFamily="@font/yaldevi_medium"
            android:textColor="#454f63"
            android:textSize="@dimen/_12sp_" />

        <TextView
            android:id="@+id/info_window_lat_lng"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="@dimen/_6dp_"
            android:fontFamily="@font/yaldevi_semi_bold"
            android:textColor="#454f63"
            android:textSize="@dimen/_12sp_" />

       </LinearLayout>

    </LinearLayout>

btn_bg_white.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#DAC9C9"
android:exitFadeDuration="@android:integer/config_shortAnimTime">

<item>
    <shape android:shape="rectangle">
        <solid android:color="@color/white" />
        <corners android:radius="8dp" />
    </shape>
</item>
<item android:id="@android:id/mask">
    <shape android:shape="rectangle">
        <solid android:color="@color/white" />
        <corners android:radius="@dimen/_8dp_" />
    </shape>
</item>
</ripple>

MapActivity.java:-

 mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
    @Nullable
    Override
    public View getInfoWindow(@NonNull Marker marker) {
    View myContentView = getLayoutInflater().inflate(
    R.layout.custom_info_window, null);
    TextView tvAddress = ((TextView) myContentView
    findViewById(R.id.info_window_address));
                
    tvAddress.setText(HelperMethods.getCompleteAddressString(MapsActivity.this, 
    marker.getPosition().latitude, marker.getPosition().longitude));
    TextView tvLatLng = ((TextView) myContentView
    findViewById(R.id.info_window_lat_lng));
                
    tvLatLng.setText(HelperMethods.convertDegMinsSecs(marker.getPosition().latitude, 
    marker.getPosition().longitude));
    return myContentView;
    }
l
            @Nullable
            @Override
            public View getInfoContents(@NonNull Marker marker) {

                return null;
            }
        });
于 2021-10-07T13:13:22.217 回答