我試圖讓滾動時工具欄在摺疊內的一個recyclerview滾動。一開始,我的繼承人主要佈局:滾動隱藏工具欄與recyclerview裏面的片段
<DrawerLayout>
<RelativeLayout
android:id="@+id/mainRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="5dp"
app:layout_scrollFlags="scroll|enterAlways"
>
</Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
<!-- ignore -->
<drawercontents>
</DrawerLayout>
所以你可能已經猜到我的片段被加載到@id/container
。我的第一個片段包含recyclerview,並且我在該回收站上設置了app:layout_behavior="@string/appbar_scrolling_view_behavior"
。這確實起作用,並且工具欄在滾動上摺疊。問題在於工具欄在未摺疊時會覆蓋片段的頂部內容。在片段容器中添加一個等於工具欄大小的頂部邊距只會導致在工具欄摺疊時(顯然)留下空白區域。
這裏缺少什麼?有任何想法嗎?
編輯:按照要求,這裏是包含recyclerview片段佈局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:id="@+id/feed"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
你可以發佈你的片段佈局嗎? – saeed
@saeed添加,檢查編輯。 – Orbit
讓我檢查我得到了同樣的問題...我解決了我自己的問題...我需要一點時間 – saeed