【问题标题】:Add round egde to a map marker向地图标记添加圆边
【发布时间】:2013-07-12 09:13:58
【问题描述】:

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

我正在使用 google mapV2。任何关于此的代码 sn-p 都会非常有帮助

【问题讨论】:

  • 你想显示圆角的信息窗口还是你放置标记的点要显示圆形?
  • @Pratik 我想用圆角显示信息窗口
  • k 等等我要发布答案。
  • 试试我的代码......如果有帮助,请告诉我......有人给了你 -1..所以尝试将你的问题发布为“如何显示带有圆角的信息窗口?”在删除问题之前请通知我。

标签: android google-maps


【解决方案1】:
 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;            

        }
    });

ma​​p_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>

【讨论】:

  • 我试过你的代码,但它的作用是它显示了一个方形边缘的视图,并且在该视图中它给出了一个圆形边缘的视图。
  • @Abhilash 尝试我编辑的答案。我刚刚将 android:background="#00ffffff" 更改为 android:background="@drawable/bg_map_info"
  • @TharakaNirmana 你能分享你的布局,如果差异那么我的答案。
  • @TharakaNirmana 嗨,我刚刚检查了它的工作情况。请为 wrap_content 设置宽度和高度,并为根布局提供一些填充。
  • @TharakaNirmana 请将您的代码放入 getInfoContents 方法并尝试。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    CustomInfoWindowLayout:-

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

    【讨论】:

      猜你喜欢
      • 2019-05-22
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 2018-05-11
      • 1970-01-01
      相关资源
      最近更新 更多