我正在尝试将对象的图像添加到信息窗口左侧的信息窗口中的自定义引脚。
我有一个调用 API 并返回具有名称和图像的对象的应用程序,我希望 InfoWindow 的左侧图标成为对象的图像,但我不知道该怎么做。
左图。
谢谢您的帮助。
对于科尔
自定义地图渲染器
public Android.Views.View GetInfoContents(Marker marker)
{
var inflater = Android.App.Application.Context.GetSystemService(Context.LayoutInflaterService) as Android.Views.LayoutInflater;
if (inflater != null)
{
Android.Views.View view;
var customPin = GetCustomPin(marker);
if (customPin == null)
{
throw new Exception("Custom pin not found");
}
view = inflater.Inflate(Resource.Layout.MapInfoWindow, null);
var infoTitle = view.FindViewById<TextView>(Resource.Id.InfoWindowTitle);
var infoSubtitle1 = view.FindViewById<TextView>(Resource.Id.InfoWindowSubtitle1);
ImageView image = view.FindViewById<ImageView>(Resource.Id.image);
Task.Run(() => {
URL url = new URL(customPin.Image);
var mIcon_val = BitmapFactory.DecodeStream(url.OpenConnection().InputStream);
image.SetImageBitmap(mIcon_val);
});
if (infoTitle != null)
{
infoTitle.Text = marker.Title;
}
if (infoSubtitle1 != null)
{
infoSubtitle1.Text = marker.Snippet;
}
return view;
}
return null;
}
地图信息窗口
<?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:orientation="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp">
<TextView
android:id="@+id/InfoWindowTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="InfoWindowTitle"
android:textColor="@android:color/black"
android:textStyle="bold" />
<TextView
android:id="@+id/InfoWindowSubtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="InfoWindowSubtitle1"
android:textColor="@android:color/black" />
</LinearLayout>
<ImageButton
android:id="@+id/InfoWindowButton"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/mtrl_btn_transparent_bg_color"
android:src="@drawable/icon_heart_red_24" />