【问题标题】:Why android snackbar is invisible with mapview?为什么使用 mapview 看不到 android 小吃吧?
【发布时间】:2020-06-12 17:23:28
【问题描述】:

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

问题

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

示例: Tap on the mapOpen apps managerOpen app again by tap in apps manager

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

当我使用android模拟器时没有任何问题(Google Pixel in different APIs: 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是否存在问题以及如何解决?

【问题讨论】:

  • 检查 findByViewId(android.R.id.content) 而不是 placesMapLayout
  • 它没有帮助:(

标签: android kotlin snackbar


【解决方案1】:
snackbar.view.post { snackbar.view.requestLayout() }

它帮助了我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 2018-07-03
    • 2018-09-12
    • 1970-01-01
    • 2020-02-20
    • 2020-10-18
    • 2016-10-12
    • 1970-01-01
    相关资源
    最近更新 更多