2017-02-12 86 views
0

就像我的标题所说的,当我通过使用协调器布局向下滚动片段中的RecycledView时,我试图动态地隐藏我的工具栏。但它不起作用。我认为这是因为我的XML文件有问题。如果有人帮助我,我会很感激。如何向下滚动片段中的recyclerView,自动隐藏工具栏?

这里是我的片段的XML文件,该片段包含制表布局内:

<RelativeLayout 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" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.jinyu.jiaodian.MainActivity" 
> 

<android.support.v7.widget.RecyclerView 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:id="@+id/my_recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical" 
    /> 
<android.support.design.widget.FloatingActionButton 
    android:id="@+id/upload_a_word" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentBottom="true" 
    android:layout_margin="@dimen/fab_margin" 
    app:srcCompat="@android:drawable/ic_input_add" 
    android:layout_alignParentRight="true" /> 

这里是我的app_bar布局:

<?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" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.example.jinyu.jiaodian.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay" 
    > 

    <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|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

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

+0

[android棒棒糖工具栏:如何在滚动时隐藏/显示工具栏?]的可能副本(http://stackoverflow.com/questions/26539623/android-lollipop-toolbar-how-to-hide-show-the -toolbar-while-scrolling) –

回答

1

app:layout_behavior="@string/appbar_scrolling_view_behavior"在您的include上,而不是在上3210。该行为是将嵌套的滚动事件传播到您的AppBarLayout

+0

嗨,谢谢你回答我,我采纳了你的建议。当我向下滚动我的回收视图时,工具栏会自动隐藏,但如果向上滚动,我的工具栏将覆盖选项卡布局的两个选项卡。我根据你的建议更新了应用栏布局的XML代码,请你带一个感谢。 – Ilovejavaing

+0

'app:layout_behavior =“@ string/appbar_scrolling_view_behavior”需要位于“CoordinatorLayout”的直接子视图上,而不是“RelativeLayout”中包含的“RecyclerView”。 – ianhanniballake

+0

谢谢你,你解决了我的问题。我真的很感激它! – Ilovejavaing

相关问题