Android-布局边框,旧的“寄宿生”仍然可见

时间:2019-03-03 20:43:46

标签: android android-layout android-xml

我有一个约束布局,在其中添加了这样的边框:

custom_info_window.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/info_window_boarder"
    >
...
...

info_window_boarder.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFF"/>
    <stroke android:width="3dip" android:color="#B1BCBE" />
    <corners android:radius="10dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>

但我仍然看到旧的“寄宿生”(白色方形寄宿生)。我该如何摆脱呢?

enter image description here

1 个答案:

答案 0 :(得分:0)

想通了。

我是在getInfoContents而不是getInfoWindow中设置“信息窗口”内容。

getInfoContents将为您提供默认的白框。如果您想要像我一样的自定义对象,则需要像这样进行getInfoWindow中的所有操作:

     mMap.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter {
        override fun getInfoWindow(marker: Marker?): View {
            val row: View = layoutInflater.inflate(R.layout.custom_info_window, null)
            val tvAddress: TextView = row.findViewById(R.id.textView_iw_address)
            val tvTime: TextView = row.findViewById(R.id.textView_iw_time)

            tvAddress.text = marker?.title
            tvTime.text = marker?.snippet

            return row            }

        override fun getInfoContents(marker: Marker?): View? {
            //put in here, if you just want the default info window
            return null
        }
    })