底部导航与协调器布局中的可滚动工具栏
问题描述:
我试图让scroll_behaviour完成我的布局。 我的问题是,如果我将底部导航换成相对布局并将其主要内容放在其上方,那么底部导航会在工具栏隐藏时滚动出屏幕。如果我将底部导航作为协调员布局的另一个直接子对象,则主要内容位于我的BottomNavigation后面。我不想通过向我的主导航底部添加填充/边距来解决此问题。你有任何提示或想法吗?
另一件事是我的底部导航的涟漪效应只在底部导航的顶部可见,而不在我的主要内容之上。
将scroll_behaviour添加到底部导航也不起作用。我想尝试一个固定的底部导航,或添加一个滚动动画,而滚动向下谷歌材料设计指南中所示。
下面的截图:
这是布局代码:
<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"/>
感谢任何帮助! 谢谢
答
您可以将协调器布局封装在相对布局中,并将该相对布局平行于协调器布局取出底部导航。
<RelativeLayout>
<android.support.design.widget.CoordinatorLayout>
...
...
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.BottomNavigationView ... />
</RelativeLayout>
谢谢奥马尔。将协调员放在另一个视图内是一个好习惯吗?我虽然已经读过协调器布局应该是父布局的地方。 – Patric
任何布局容器都可以是父级,并且在您的特殊情况下,底部导航不是用协调器布局设计的,因此您不能直接在协调器布局内放置底部导航以正常工作。 –
您可以做的另一件事是将底部导航放置在您的coordinatorLayout中的相对布局中,但我不知道它是否会禁用滚动或不是用于底部导航。 –