android - 带有协调器 View 的 snackbar 出现后布局 View 卡住

标签 android android-fragments android-mapview android-snackbar

我已经成功地使用围绕 fragment 中 MapView 的协调器布局成功地展示了 snackbar 。 map View 成功向上滑动,为 snackbar 留出空间,但是,一旦 snackbar 消失, View 就会保持原样,并在 snackbar 出现的地方留下一个白色的酒吧。我怎样才能解决这个问题?我目前在 map View 上应用以下代码作为行为:

    @Override
    public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
        float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
        child.setTranslationY(translationY);
        return true;
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
        // we only want to trigger the change
        // only when the changes is from a snackbar
        return dependency instanceof Snackbar.SnackbarLayout;
    }

我的 fragment View 是这样的:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/places_coordinator_layout"
    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="match_parent">

    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="com.adamshort.canieatthis.FloatingActionButtonBehaviour"/>

</android.support.design.widget.CoordinatorLayout>

我试过四处搜索,但要么我搜索的是错误的东西,要么我没有人遇到过类似的问题。我已经看到我在各种教程和视频中发布并成功运行的行为代码,但它在 map View 中表现不佳。有什么想法吗?

最佳答案

拜托,我下面的回答是试图帮助你......如果对你有帮助,请告诉我......然后,如果它没有用,我会删除......

也许,您需要定义并定位到您的 MapView。在我的例子中,我必须在底部创建一个虚拟 View 并将其设置为将随 SnackBar 移动的 View 的 archor

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/places_coordinator_layout"
    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="match_parent">

    <android.support.v4.widget.Space
        android:id="@+id/anchor"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/transparent"
        android:layout_gravity="bottom" />

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_anchor="@id/anchor"
            app:layout_behavior="com.adamshort.canieatthis.FloatingActionButtonBehaviour"/>

</android.support.design.widget.CoordinatorLayout>

关于android - 带有协调器 View 的 snackbar 出现后布局 View 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37264484/

相关文章:

android - 从 MainActivity 调用 Fragment 中的方法

java - NavigationDrawer fragment 样式/图标

java - 如何在两个不同的类中使用同一个计数器

android - 如何在谷歌地图上获取按钮字段

除非您触摸 map View ,否则不会加载 Android MapView

java - 文件访问android

android - DefaultHttpClient 类 Android 中的超时

android - 如何使用平台和构建工具在 RHEL linux 上安装 Android sdk

Android:如何拖动(移动)PopupWindow?

android - 在旋转和返回时恢复 MapView 的状态