我可以通过将drawable设置为InfoWindowAdapter的视图背景来自定义infowindow。但是,我不知道如何绘制infowindow的锚定部分。
这就是我所做的。
InfoWindowAdapter
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private Context context;
private PelicanApplication appState;
public MarkerInfoWindowAdapter(Context context,Activity act)
{
this.context=context;
appState = ((PelicanApplication)act.getApplication());
}
@Override
public View getInfoWindow(Marker marker)
{
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.custom_infowindow, null);
return v;
}
@Override
public View getInfoContents(Marker marker)
{
return null;
}
}
InfoWindow查看
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical" android:layout_width="300dp"
android:background="@drawable/bg_infowindow"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:textColor="@color/primary_text_color"
android:id="@+id/lbl_pickup_address"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/primary_text_color"
android:text="(1km, 5min)"
android:id="@+id/lbl_info_to_get_sender"
android:layout_gravity="center_horizontal" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_divider_width"
android:background="@color/selector_color"
android:layout_marginTop="@dimen/drawer_divider2line_width" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:textColor="@color/primary_text_color"
android:id="@+id/lbl_recipient_address"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/primary_text_color"
android:text="(1km, 5min)"
android:id="@+id/lbl_info_to_get_recipient"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textColor="@color/primary_text_color"
android:id="@+id/lbl_price"
android:layout_gravity="center_horizontal"
android:textSize="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/primary_text_color"
android:text="(1km, 5min)"
android:id="@+id/lbl_package_details"
android:layout_gravity="center_horizontal" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_divider_width"
android:background="@color/selector_color"
android:layout_marginTop="@dimen/drawer_divider2line_width" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_view_details"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/primary_text_color"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="View Details"
android:layout_gravity="center_vertical" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_divider_width"
android:background="@color/selector_color"
android:layout_marginTop="@dimen/drawer_divider2line_width" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_accept_delivery"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/primary_text_color"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Accept this Delivery"
android:layout_gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
如您所见,我将 bg_infowindow 设为背景。
bg_infowindow.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/primary_color" />
<stroke android:width="1dp"
android:color="@color/selector_color" />
<corners
android:radius="5dp" />
</shape>
到目前为止我得到了什么
我想要什么(我标记了我想要绘制的部分)。在此屏幕截图中,锚点位于infowindow的右侧。我希望它在infowindow的底部
我不想将图片设置为背景