gpt4 book ai didi

android - Bottom Sheet 内的谷歌地图 View

转载 作者:搜寻专家 更新时间:2023-11-01 07:46:12 26 4
gpt4 key购买 nike

我想做一个这样的 View Sample image

其中想要在 Bottom Sheet fragment 中显示谷歌地图。

我尝试过的

我尝试在 Bottom Sheet 对话框 fragment 中显示 map ,但输出不是我想要的。

我需要的是一个固定大小的 View ,它应该能够显示 map 。目前,我的 View 也在响应用户手势以更改 Bottom Sheet 状态,但我需要手势仅在 map 上工作(例如,用于 map 平移)。

最佳答案

当我们在 BottomSheet 上使用 map 时,它会与触摸事件发生冲突。因此,需要禁止触摸 BottomSheet

请在下面找到允许 map 移动的自定义类。

public class BottomSheetMapView extends MapView {

public BottomSheetMapView(Context context) {
super(context);
}

public BottomSheetMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public BottomSheetMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public BottomSheetMapView(Context context, MapboxMapOptions options) {
super(context, options);
}
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
getParent().requestDisallowInterceptTouchEvent(false);
break;
default:
break;
}

return super.onInterceptTouchEvent(event);
}

我正在使用 Mapbox。所以,我在 xml 中使用 com.example.BottomSheetMapView 而不是 com.mapbox.mapboxsdk.maps.MapView。同样,您可以使用谷歌地图。

这满足你的要求。

关于android - Bottom Sheet 内的谷歌地图 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43790239/

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