简体   繁体   English

使用 Coordinator 布局时,SnackBar 显示在一定高度以上

[英]SnackBar showing above a certain height when using Coordinator layout

So I have the coordinate layout as the root layout as I am using a floating Action button.因此,当我使用浮动操作按钮时,我将坐标布局作为根布局。 Here is my xml.这是我的 xml。

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:android="http://schemas.android.com/apk/res/android"
        tools:context=".activities.teacher.TeacherJobBoard"
        android:id="@+id/rootLayout_job_board"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <View
        android:id="@+id/anchor"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/color_black_darker_overlay"
        android:layout_gravity="bottom"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/all_night_background"
        android:orientation="vertical"
        tools:context=".activities.teacher.TeacherJobBoard">

        <com.hugocastelani.waterfalltoolbar.WaterfallToolbar
            android:id="@+id/teacher_job_board_waterfall_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:final_elevation="15dp">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/teacher_job_board_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/tutor_bear_dark_blue"
                android:minHeight="?attr/actionBarSize"
                android:theme="?attr/actionBarTheme" />

        </com.hugocastelani.waterfalltoolbar.WaterfallToolbar>


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/discretescrollview_teacherJobBoard"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" />



    </LinearLayout>

    <com.github.ybq.android.spinkit.SpinKitView
        android:id="@+id/spin_kit_job_board"
        style="@style/SpinKitView.Large.WanderingCubes"
        android:layout_width="@dimen/_80sdp"
        android:layout_height="@dimen/_80sdp"
        android:layout_gravity="center_horizontal|center_vertical"
        app:SpinKit_Color="@color/color_white" />

    <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
        android:id="@+id/extended_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:gravity="center"
        style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton.Icon"
        android:onClick="expand"
        app:iconSize="@dimen/_12sdp"
        android:elevation="@dimen/_5sdp"
        android:fontFamily="@font/roboto_light"
        android:textColor="@color/white"
        android:text="Filter"
        app:iconPadding="@dimen/_5sdp"
        android:layout_marginBottom="@dimen/_10sdp"
        android:layout_marginRight="@dimen/_10sdp"
        app:backgroundTint="@color/tutor_bear_dark_blue"
        app:iconTint="@color/white"
        app:icon="@drawable/ic_filter"
        />

    <View
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/color_black_darker_overlay"
        android:visibility="gone"
        />
<include layout="@layout/bottom_filter_dialog"
    android:id="@+id/filterSheet"
    android:visibility="gone"
    />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

I have a simple snack bar in my code like this.我的代码中有一个简单的小吃店,就像这样。

Snackbar.make(binding.getRoot(), "This is main activity", Snackbar.LENGTH_LONG)
                    .setAction("CLOSE", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                        }
                    }). show();

Problem is when I show the snack bar , it always appears above a certain height from the bottom of the screen.问题是当我显示小吃店时,它总是出现在距屏幕底部一定高度的上方。 As if there is some kind of a bottom margin set.好像有某种底部边距设置。 This only happens when I use coordinate layout.这仅在我使用坐标布局时发生。 Snackbar works fine in other layouts. Snackbar 在其他布局中也能正常工作。 Picture of the problem is given as a reference.给出问题的图片作为参考。

在此处输入图片说明

Give the root view instead, rootLayout_job_board改为提供根视图, rootLayout_job_board

CoordinatorLayout rootLayout = findViewById(R.id.rootLayout_job_board);
Snackbar.make(rootLayout), "This is main activity", Snackbar.LENGTH_LONG)
                .setAction("CLOSE", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                }). show();

If that doesn't work, try giving GRAVITY using LayoutParams如果这不起作用,请尝试使用LayoutParams赋予GRAVITY

If that doesn't work, also give margins as 0 in LayoutParams.如果这不起作用,还可以在 LayoutParams 中将边距设置为 0。 Also, if your device is Above 9 then you should consider navigation gestures,此外,如果您的设备高于 9,那么您应该考虑导航手势,

snackbar.isGestureInsetBottomIgnored(false); See here 看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM