我们很难在 Android 上顺利调整此处的 SDK 地图的大小。
我们希望将地图平滑地调整到底部工作表的 collapse
和 hidden
状态,如 中所示
但是正如您所看到的,它并没有真正调整大小,而是跳转到新位置,而地图保持其尺寸并且不缩放。
这就是我们所做的:
...
<com.here.sdk.mapview.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/nine_grid_unit" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/menuBottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true"
android:elevation="@dimen/four_grid_unit"
android:focusable="true"
app:behavior_hideable="true"
app:behavior_peekHeight="@dimen/thirtytwo_grid_unit"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View
android:id="@+id/tap_stop"
android:layout_width="@dimen/nine_grid_unit"
android:layout_height="@dimen/one_grid_unit"
android:layout_marginTop="@dimen/one_grid_unit"
android:background="@color/grey_light"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<edeka.digital.app.widget.SegmentedControlView
android:id="@+id/tabSwitchSegmentedControl"
android:layout_width="@dimen/thirtyfive_grid_unit"
android:layout_height="wrap_content"
android:paddingStart="@dimen/three_grid_unit"
android:paddingEnd="@dimen/three_grid_unit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tap_stop"
app:segmentCount="2"
app:segmentTitles="@array/segment_titles_shop_search" />
</androidx.constraintlayout.widget.ConstraintLayout>
...
和代码:
val bottomBehavior = BottomSheetBehavior.from(binding.menuBottomSheet)
bottomBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
val mapView = binding.map
override fun onSlide(bottomSheet: View, slideOffset: Float) {
}
override fun onStateChanged(bottomSheet: View, newState: Int) {
bottomSheetBehaviorObservable.onNext(newState)
when (newState) {
BottomSheetBehavior.STATE_COLLAPSED -> {
mapView.bottom = binding.menuBottomSheet.top
mapView.invalidate()
}
BottomSheetBehavior.STATE_HIDDEN -> {
mapView.bottom = binding.menuBottomSheet.top
mapView.invalidate()
}
else -> { /* void */
}
}
}
})
我希望有某种 resize() 函数,或者如果布局尺寸发生变化,它会自行布局。
我们真正想要的已经在 HERE WeGo 应用中实现了。如果用户滑动底部表格,则整个地图都会缩放(包括此处的徽标):
有人可以帮助我们吗?
可以在此处找到 1 中显示的演示:
答案 0 :(得分:1)
看起来您的地图视图被滑动面板覆盖,并且在幻灯片动画期间没有重绘。它仅在状态更改时呈现。您可以尝试在 mapView.invalidate()
方法中添加 onSlide
,如下所示:
override fun onSlide(bottomSheet: View, slideOffset: Float) {
mapView.invalidate()
}
但是,为了确定这是否是真正的原因,我需要获取并构建您的代码。
答案 1 :(得分:1)
我能够获取您的代码,编译并重现该错误。我找到了两个选项来解决这个问题,都在模拟器和真实设备上进行了测试。
将状态更改处理代码中的代码复制到 onSlide
方法中:
override fun onSlide(bottomSheet: View, slideOffset: Float) {
mapView.bottom = binding.menuBottomSheet.top
mapView.invalidate()
}
完全删除地图视图调整大小和无效代码。它基本上使整个 setupBottomSheet
方法变得多余。地图视图无需调整大小即可正常工作,这是一种更可取的修复方法,因为它涉及的代码和操作较少。
答案 2 :(得分:1)
我发现实现它的最佳解决方案是添加一个新方法:
private fun updateMapView(bottomSheetTop: Int) {
val mapView = binding.map
val principalY = Math.min(bottomSheetTop / 2.0, mapView.height / 2.0)
mapView.camera.principalPoint = Point2D(mapView.width / 2.0, principalY)
val logoMargin = Math.max(0, mapView.bottom - bottomSheetTop)
mapView.setWatermarkPosition(WatermarkPlacement.BOTTOM_CENTER, logoMargin.toLong())
}
并像这样在 onSlide
和 onStateChanged
中调用它:
updateMapView(bottomSheet.top)
注意底部中心位置需要有HERE标志,否则无法使用可调整的边距。
我也试图调整地图视图的大小,但结果并不令人满意。如果您想尝试,这里是代码:
private fun updateMapView(bottomSheetTop: Int) {
val mapView = binding.map
mapView.layoutParams.height = bottomSheetTop
mapView.requestLayout()
}