2016-02-28 62 views
5

我有一个布局(由android studio生成),其中我添加了一个RelativeLayout到AppBarLayout。代码如下,它看起来像这样:使用CoordinatorLayout来滚动RecyclerView时隐藏/显示RelativeLayout

enter image description here

我在哪里卡住:我想实现滚动Recyclerview当下来我要的是绿色的相对布局(具有ID“controlContainer” )与它滚动,当我向上滚动它应该滚动(不只是在顶部,但在任何地方我滚动列表中)

顶部的工具栏应该留在它的位置。

<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=".MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    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" 
     app:popupTheme="@style/AppTheme.PopupOverlay" 
     /> 

    <RelativeLayout 
     android:id="@+id/controlContainer" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:background="@android:color/holo_green_dark" 
     app:layout_scrollFlags="scroll|enterAlways"></RelativeLayout> 

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


<FrameLayout 
    android:id="@+id/frameLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <include layout="@layout/venue_list" /> 
</FrameLayout> 

我认为,在应与app:layout_behavior="@string/appbar_scrolling_view_behavior"远离滚动合并应达到该视图使用app:layout_scrollFlags="scroll|enterAlways",但它不会做任何事情。或者,当我将这些字段添加到工具栏本身时,两个布局都会滚动 - 这不是我想要的,我希望工具栏始终保持固定。

如果有人能指出我在正确的方向吗? (我希望这将有可能使用协调布局,而不是黑客与onscroll听众一些布局操作?)

+0

你有没有找到解决方案?我有完全相同的问题... thx – Blunderer

+0

不幸的是,我没有找到一个可接受的解决方案 – stamanuel

回答

0

试试这个在您的工具栏代码:

app:layout_collapseMode="pin" 
app:layout_scrollFlags="scroll|enterAlways" 

我发现这个链接有用:Scrolling Toolbar

+1

我玩过这些值,但是当我按照你的建议,然后工具栏和相对布局滚动。 但我想工具栏保持固定,只是相对布局滚动:( – stamanuel

相关问题