我需要在标记的Button中有一个ProgressBarInfoWindow。我有两个主要问题:


InfoWindow不太适合包含我需要的文本。
我不知道如何在InfoWindow中添加任何对象。


这是我的地图以及用于生成标记的代码的外观:

android - 如何在InfoWindow中添加对象使其变大-LMLPHP

MarkerOptions markerOptions = new MarkerOptions().position(enemy.position).title("Mostro " + enemy.nome).snippet("Livello " + enemy.level + "\n" + enemy.health());
map.addMarker(markerOptions);


如您所见,我在代码段中写的其余文本没有显示。

我该如何解决这两个问题?
预先感谢您的耐心和考虑。

最佳答案

为信息窗口创建一个自定义布局,如下所示,并使用此布局初始化infowindowadapter:

******** InfoWindow ********

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <RelativeLayout
            android:layout_gravity="center"
            android:layout_width="300dp"
            android:layout_height="wrap_content">

        <TextView
                android:id="@+id/location_tv"
                android:textStyle="bold"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:gravity="center"
                android:text="BluePearl Veterinary Partners"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
                android:textColor="@color/about_color"
                android:layout_centerHorizontal="true"/>

        <LinearLayout
                android:layout_marginTop="16dp"
                android:gravity="center_vertical"
                android:layout_below="@+id/location_tv"
                android:id="@+id/direction_layout"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">



            <ImageView
                    android:id="@+id/direction_imageview"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:scaleType="fitXY"
                    android:layout_marginStart="16dp"
                    android:src="@drawable/ic_place" />

            <TextView
                    android:id="@+id/address_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginEnd="16dp"
                    android:text="1 West 15th Street, New York, NY, 10011"
                    android:layout_toRightOf="@+id/direction_imageview"
                    android:layout_below="@+id/location_tv"
                    android:textSize="13sp"
            />


        </LinearLayout>

        <LinearLayout
                android:layout_marginTop="12dp"
                android:gravity="center_vertical"
                android:id="@+id/phone_layout"
                android:layout_below="@+id/direction_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            <ImageView
                    android:id="@+id/phone_imageview"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_marginStart="16dp"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/direction_imageview"
                    android:src="@drawable/phone_red" />

            <TextView
                    android:id="@+id/ph_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:textSize="13sp"
                    android:text="212-924-3311"
                    android:layout_toRightOf="@+id/phone_imageview"
                    android:layout_below="@+id/address_tv" />

        </LinearLayout>




        <View
                android:layout_below="@+id/phone_layout"
                android:layout_width="match_parent"
                android:layout_height="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"/>



    </RelativeLayout>

</LinearLayout>


******** InfoWindow.kt ********

class InfoWindow(private val context: Context) : GoogleMap.InfoWindowAdapter {

    override fun getInfoWindow(marker: Marker): View? {
        return null
    }
    override fun getInfoContents(marker: Marker): View {
        val view = (context as Activity).layoutInflater
            .inflate(R.layout.info_window_map, null)
        val location_tv = view.findViewById<TextView>(R.id.location_tv)
        val address_tv = view.findViewById<TextView>(R.id.address_tv)
        val phone_tv = view.findViewById<TextView>(R.id.ph_tv)
        val directoryModel = marker.tag as HospitalsList?
        if (directoryModel != null) {
            location_tv.text = directoryModel.title
            address_tv.text = directoryModel.address
            phone_tv.text = directoryModel.contactnumber
        }
        return view
    }
}


******** MapActivity.kt ********

在您要初始化地图片段的MapActivity中,使用以下代码行:

val customInfoWindow = InfoWindow(this)
   map.setInfoWindowAdapter(customInfoWindow)

关于android - 如何在InfoWindow中添加对象使其变大,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53724258/

10-13 00:13