Подтвердить что ты не робот

Android BottomSheet: скрывается под панелью инструментов

Я попытался использовать новый нижний лист из библиотеки поддержки 23.2.0, чтобы развернуть нижний лист до полного экрана, как предложено в рекомендациях по проектированию.

Это работает очень хорошо, но нижний лист находится под моим ActionBar и под моими вкладками.

Как можно позволить нижнему листу пройти над панелью инструментов? Мое меню структурировано так:

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|snap|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <include
        android:id="@+id/playerLayout"
        layout="@layout/player_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_peekHeight="?attr/actionBarSize"
        app:layout_behavior="@string/bottom_sheet_behavior"
        app:model="@{model}"/>

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

enter image description here

4b9b3361

Ответ 1

AppBarLayout имеет значение по умолчанию 4dp (значение ресурса измерения design_appbar_elevation).

По умолчанию CoordinatorLayout, как и любой FrameLayout, будут элементы макета с более высокой высотой перед более низкой высотой на устройствах API 21 и выше.

Попробуйте добавить android:elevation="@dimen/design_appbar_elevation" в свой макет.

Обратите внимание, что высота модального нижнего листа @dimen/design_bottom_sheet_modal_elevation == 16dp

Ответ 2

Если приведенный выше ответ не помогает, попробуйте установить на свой BottomSheet:

android:elevation="@dimen/design_appbar_elevation" android:fitsSystemWindows="true"

и создайте свой фрагмент таким образом:

videoFragment = VideoFragment.newInstance(); getSupportFragmentManager().beginTransaction().replace(R.id.video_fragment, videoFragment).commit();
не так: videoFragment = (VideoFragment) getSupportFragmentManager().findFragmentById(R.id.video_fragment);

Например у меня такая раскладка:

<android.support.design.widget.CoordinatorLayout
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:background="@color/activity_background">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

    <include layout="@layout/toolbar"/>

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

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    app:itemBackground="@color/white"
    app:menu="@menu/bottom_navigation_main"/>

<FrameLayout
    android:id="@+id/video_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="@dimen/design_appbar_elevation"
    android:fitsSystemWindows="true"
    app:behavior_hideable="true"
    app:behavior_peekHeight="0dp"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>


и это не работает без указанных вещей