2017-02-12 50 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

相關問題