Нижняя панель навигации скрывается при попытке прокрутки

У меня есть активность с нижней панелью навигации (через библиотеку roughike BottomBar). Это выглядит так: введите здесь описание изображения

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

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

Но если страница содержит контент более чем на один экран, то нижняя панель должна скрываться при прокрутке (и теперь это работает нормально).

В моем коде нет слушателей для прокрутки, и мой xml-файл выглядит так:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".presentation.ui.mainactivity.MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mainCord" >

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            android:background="@color/primary"
            android:theme="@style/ToolbarStyle"
            app:titleTextAppearance="@style/ToolbarStyle" />

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

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

    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottomBar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_gravity="bottom"
        app:bb_tabXmlResource="@xml/bottom_bar_tabs"
        app:bb_activeTabColor="@color/white"
        app:bb_inActiveTabColor="@color/bottom_bar_inactive_tab"
        app:bb_inActiveTabAlpha="1"
        app:bb_behavior="shy|shifting" />
</android.support.design.widget.CoordinatorLayout>

Я искал решение для своей проблемы, но ничего не нашел. Что я могу сделать, чтобы избежать этого эффекта?

ОБНОВЛЕНО:

FAB находится внутри ViewPager. Макет вкладки на скриншоте выглядит так:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/eventCoordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh"
        android:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <android.support.v7.widget.RecyclerView
            android:id="@+id/eventsRecyclerView"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity = "center"
        android:gravity="center" >

        <TextView
            android:id="@+id/emptyText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/secondary_text"
            android:textSize="16sp"
            android:gravity="center"
            android:text="@string/empty_events_text"
            android:drawableTop="@drawable/ic_no_calendar"
            android:drawablePadding="4dp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/createEventText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/create_event_text"
            android:textColor="@color/secondary_text"
            android:textSize="16sp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/createEventButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/primary"
            android:text="@string/create_event"
            android:textSize="16sp"
            android:visibility="gone" />
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/createEvent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:src="@drawable/ic_add_white_24dp"
        style="@style/floating_action_button"
        app:layout_anchor="@id/eventsRecyclerView"
        app:layout_anchorGravity="bottom|end"
        app:borderWidth="0dp"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp" />

    <RelativeLayout
        android:id="@+id/loadingPanel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center" >

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:indeterminate="true" />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

person Danil Prokhorenko    schedule 21.11.2016    source источник
comment
Эй, я не вижу твоего потрясающего кода. Это внутри вашего фрагмента просмотра?   -  person Tas    schedule 21.11.2016
comment
@Tasneem, ты прав. Я добавил макет своего фрагмента в вопрос.   -  person Danil Prokhorenko    schedule 21.11.2016


Ответы (3)


приложение:bb_behavior="underNavbar"

У вас есть проблема в следующем коде

<com.roughike.bottombar.BottomBar
    android:id="@+id/bottomBar"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_gravity="bottom"
    app:bb_tabXmlResource="@xml/bottom_bar_tabs"
    app:bb_activeTabColor="@color/white"
    app:bb_inActiveTabColor="@color/bottom_bar_inactive_tab"
    app:bb_inActiveTabAlpha="1"
    app:bb_behavior="shy|shifting" />

заменить

app:bb_behavior="shy|shifting"

с

app:bb_behavior="underNavbar"

Надеюсь, что это работает для вас!

person android_griezmann    schedule 21.11.2016
comment
В этом случае нижняя полоса никогда не прячется. Но я хочу скрыть нижнюю панель при прокрутке содержимого. И не скрывайте, когда я просто пытаюсь прокрутить, но весь контент лежит на экране. - person Danil Prokhorenko; 21.11.2016
comment
Пожалуйста, разработайте свой сценарий правильно... Непонятно - person Bhavnik; 21.11.2016

Проверьте свой ФАЙЛ манифеста и убедитесь, что вы не используете полноэкранную тему... Однако вы можете использовать следующий код, чтобы скрыть и показать панель на Android выше, чем API 19. Чтобы скрыть панель, просто измените VISIBLE на GONE, и убедитесь, что вы вызываете метод showNavBar() как в методе onCreate(), так и в методе onResume().

public void showNavBar() {
        View view = getWindow().getDecorView();
        view.setSystemUiVisibility(View.VISIBLE);
}
person OGx09    schedule 21.11.2016

У меня была такая же проблема, я исправил ее, выполнив следующие действия:

В activity_main.xml добавьте это в CoordinatorLayout:

android:fitsSystemWindows="true"

viewpager должен быть таким:

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

И во всех ваших фрагментах они должны начинаться с NestedScrollView и должны содержать (fillViewport):

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context="com.khan.junaid.phonefans.MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fans_list_view"
        />

</android.support.v4.widget.NestedScrollView>

Эти настройки сделают фрагменты прокручиваемыми, и контент больше не будет прятаться за кнопками панели навигации.

person Junaid Khan    schedule 25.02.2018