【发布时间】:2016-06-11 08:32:54
【问题描述】:
我有一个布局(由 android studio 生成),我在其中向 AppBarLayout 添加了一个 RelativeLayout。代码如下,看起来像这样:
我卡住的地方:我想要实现的是向下滚动 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_scrollFlags="scroll|enterAlways" 结合 app:layout_behavior="@string/appbar_scrolling_view_behavior" 应该可以实现这一点,但它没有做任何事情。或者,当我将这些字段添加到工具栏本身时,两个布局都会滚动 - 这不是我想要的,我希望工具栏始终保持固定。
如果有人能在这里指出我正确的方向会很好吗? (我希望可以使用协调器布局而不是使用 onscroll 侦听器进行一些布局操作?)
【问题讨论】:
-
您找到解决方案了吗?我有完全相同的问题...谢谢
-
很遗憾我还没有找到可接受的解决方案
标签: android coordinator-layout