[英]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.