0

黑客,底部導航與協調器佈局中的可滾動工具欄

我試圖讓scroll_behaviour完成我的佈局。 我的問題是,如果我將底部導航換成相對佈局並將其主要內容放在其上方,那麼底部導航會在工具欄隱藏時滾動出屏幕。如果我將底部導航作爲協調員佈局的另一個直接子對象,則主要內容位於我的BottomNavigation後面。我不想通過向我的主導航底部添加填充/邊距來解決此問題。你有任何提示或想法嗎?

另一件事是我的底部導航的漣漪效應只在底部導航的頂部可見,而不在我的主要內容之上。

將scroll_behaviour添加到底部導航也不起作用。我想嘗試一個固定的底部導航,或添加一個滾動動畫,而滾動向下谷歌材料設計指南中所示。

下面的截圖:

App Screenshot

這是佈局代碼:

<android.support.design.widget.CoordinatorLayout 
android:id="@+id/main_content" 
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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 

> 

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


    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?android:attr/actionBarSize" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:layout_scrollFlags="scroll|enterAlways" 
     > 

    </android.support.v7.widget.Toolbar> 


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

<RelativeLayout 
    android:id="@+id/rl" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    > 
    <com.getproperly.properlyv2.classes.misc.CustomViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

</RelativeLayout> 

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottom_navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_anchorGravity="bottom" 
    app:layout_anchor="@id/rl" 
    app:menu="@menu/bottom_navigation_main" 
    /> 

<com.getproperly.properlyv2.classes.misc.SelfAwareFloatingActionButton 
    android:id="@+id/fab_add" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_add_white" 
    app:fabSize="normal" 
    app:layout_anchor="@id/rl" 
    app:layout_anchorGravity="bottom|right|end" 
    app:layout_behavior="com.getproperly.properlyv2.classes.misc.ScrollAwareFABBehavior" 
    android:layout_marginEnd="@dimen/fab_margin" 
    android:layout_marginLeft="@dimen/fab_margin" 
    android:layout_marginRight="@dimen/fab_margin" 
    android:layout_marginStart="@dimen/fab_margin" 
    android:layout_marginTop="@dimen/fab_margin" 
    android:layout_marginBottom="64dp"/> 

感謝任何幫助! 謝謝

回答

2

您可以將協調器佈局封裝在相對佈局中,並將該相對佈局平行於協調器佈局取出底部導航。

<RelativeLayout> 

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

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

</RelativeLayout> 
+0

謝謝奧馬爾。將協調員放在另一個視圖內是一個好習慣嗎?我雖然已經讀過協調器佈局應該是父佈局的地方。 – Patric

+0

任何佈局容器都可以是父級,並且在您的特殊情況下,底部導航不是用協調器佈局設計的,因此您不能直接在協調器佈局內放置底部導航以正常工作。 –

+0

您可以做的另一件事是將底部導航放置在您的coordinatorLayout中的相對佈局中,但我不知道它是否會禁用滾動或不是用於底部導航。 –