首页 > 解决方案 > 为什么使用 mapview 看不到 android 小吃吧?

问题描述

我正在使用 Yandex MapKit 的地图。当用户点击地图时,我向他显示搜索结果,添加地标并显示带有位置名称和按钮的小吃栏。

问题

在我的小米设备(小米米 9、android 9)上存在快餐栏,但在未执行某些操作之前它是不可见的。

示例: 点击地图 打开应用程序管理器 通过在应用程序管理器中点击再次打开应用程序

我还可以打开搜索编辑(地图顶部),然后会显示小吃吧。当snackbar不可见时,它存在:我可以点击snackbar按钮半径,按钮的动作将运行!

当我使用android模拟器时没有任何问题(不同API中的Google Pixel:23、28、29 ...)

我的活动 XML:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/placesMapLayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".activities.PlacesMapActivity">

<com.yandex.mapkit.mapview.MapView
    android:id="@+id/placesMapView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/outlinedTextField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:boxBackgroundColor="@color/white"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_margin="20dp"
    android:hint="@null">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/searchEdit"
        android:imeOptions="actionSearch"
        android:inputType="text"
        app:boxBackgroundColor="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

</RelativeLayout>

Snackbar 创建(Kotlin):

val snackbar = Snackbar.make(placesMapLayout, foundObject.name.toString(), Snackbar.LENGTH_INDEFINITE)

我试图为 mapView 设置 layout_height 以获得活动底部的空白位置。它已经奏效了:screenshot。一键和小吃店可见!但我不想裁剪我的地图。

那么,mapView是否存在问题以及如何解决呢?

标签: androidkotlinsnackbar

解决方案


snackbar.view.post { snackbar.view.requestLayout() }

它帮助了我。


推荐阅读