如何在 InfoWindow 中添加对象使其变大
How to add objects in an InfoWindow making it larger
我需要在标记的 InfoWindow
中有一个 Button
和一个 ProgressBar
。我有两个主要问题:
InfoWindow
不够大,无法包含我需要的文本。
- 我不知道如何在
InfoWindow
中添加任何类型的对象。
这是它在我的地图中的样子以及我用来生成标记的代码:
MarkerOptions markerOptions = new MarkerOptions().position(enemy.position).title("Mostro " + enemy.nome).snippet("Livello " + enemy.level + "\n" + enemy.health());
map.addMarker(markerOptions);
如您所见,我在代码段中编写的其余文本未显示。
我该如何解决这两个问题?
预先感谢您的耐心和考虑。
如下所示为信息 window 创建自定义布局,并使用此布局初始化您的信息window适配器:
********信息窗口********
<?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)
我需要在标记的 InfoWindow
中有一个 Button
和一个 ProgressBar
。我有两个主要问题:
InfoWindow
不够大,无法包含我需要的文本。- 我不知道如何在
InfoWindow
中添加任何类型的对象。
这是它在我的地图中的样子以及我用来生成标记的代码:
MarkerOptions markerOptions = new MarkerOptions().position(enemy.position).title("Mostro " + enemy.nome).snippet("Livello " + enemy.level + "\n" + enemy.health());
map.addMarker(markerOptions);
如您所见,我在代码段中编写的其余文本未显示。
我该如何解决这两个问题?
预先感谢您的耐心和考虑。
如下所示为信息 window 创建自定义布局,并使用此布局初始化您的信息window适配器:
********信息窗口********
<?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)