gpt4 book ai didi

android - 如何为谷歌地图设置自定义标记标题

转载 作者:行者123 更新时间:2023-12-04 13:02:57 24 4
gpt4 key购买 nike

如何设置包含信息和按钮的样式自定义标记标题/fragment ?我已经有一个自定义标记图标图像集。现在我需要一个自定义弹出窗口,当用户点击标记时,它将包含某些信息和一个按钮。

这与我想要实现的目标很接近。

自定义标题/fragment 示例

Custom title/snippet example

 LatLng huduma_gpo = new LatLng(-1.280694, 36.818277);
googleMap.addMarker(new MarkerOptions().position(huduma_gpo).title("Huduma center GPO")).setIcon(BitmapDescriptorFactory.fromBitmap(marker));

// For zooming automatically to the location of the marker
googleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(huduma_gpo , 12.0f) );

最佳答案

使用自定义布局设计并将其添加到您的 Google map 中。在这里引用下面的示例代码并自定义您的设计。

橱窗设计:

<?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:background="@drawable/custom_info_bubble"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">

<ImageView
android:id="@+id/badge"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/text_lay"
android:background="@drawable/icn_right_arrow" />

<LinearLayout
android:id="@+id/text_lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="3dp">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:padding="3dp"
android:singleLine="true"
android:text="title"
android:textColor="#ff000000"
android:textSize="@dimen/text_size_small" />

<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:fontFamily="sans-serif"
android:padding="3dp"
android:text="45 bays available"
android:textColor="@color/green"
android:textSize="14dp" />
</LinearLayout>

</RelativeLayout>

窗口适配器的 Java 类:
public class InfoWindowAdapter implements GoogleMap.InfoWindowAdapter, CommonValues, BundleTags {

private View view;

private FragmentActivity myContext;

public InfoWindowAdapter(FragmentActivity aContext) {
this.myContext = aContext;

LayoutInflater inflater = (LayoutInflater) myContext.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

view = inflater.inflate(R.layout.layout_inflate_parking_info_window,
null);
}

@Override
public View getInfoContents(Marker marker) {

if (marker != null
&& marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
return null;
}

@Override
public View getInfoWindow(final Marker marker) {

final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
titleUi.setVisibility(View.GONE);
}

final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view
.findViewById(R.id.snippet));

if (snippet != null) {

String[] SnippetArray = snippet.split(SEPARATOR);


snippetUi.setText(SnippetArray[0]);
} else {
snippetUi.setText("");
}

return view;
}
}

关于android - 如何为谷歌地图设置自定义标记标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50603849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com