[英]Android: GoogleMaps marker details fragment
是的,您可以使用这个库轻松实现它,它在最小化和拉伸时支持 2 种布局,我在谷歌地图应用程序之后实现了类似的行为,获取如下数据并将其设置在布局中
样本用法是
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Main Content"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text="The Awesome Sliding Up Panel"
android:textSize="16sp" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
我想到了。 我需要的是一个底页对话框。 这是我用作灵感来源的非常有用的指南。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="bottom">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Rent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
@Override
public boolean onMarkerClick(Marker marker) {
showBottomSheetDialog();
return false;
}
布局与底部对齐。
private void showBottomSheetDialog() { final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getContext()); bottomSheetDialog.setContentView(R.layout.MY_LAYOUT_NAME); AppCompatButton btn = bottomSheetDialog.findViewById(R.id.btn_view); bottomSheetDialog.show(); }
确保处理 MapSupportFragment 的 class 实现OnMapReadyCallback
、 GoogleMap.OnMarkerClickListener
和(如果需要标记集群) ClusterManager.OnClusterItemClickListener
。 覆盖必要的方法:
@Override public boolean onMarkerClick(Marker marker) { showBottomSheetDialog(); return false; }
如果您需要集群,请不要忘记在 @onMapReady() 中添加:
map.setOnCameraIdleListener(clusterManager); map.setOnMarkerClickListener(clusterManager); clusterManager.setOnClusterItemClickListener(this);
瞧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.