我知道以下內容不正確,但我想您可以將其視爲僞代碼。我想知道,我怎樣才能將整個佈局「附加」到我的RecyclerView,以便當我向下滾動佈局時,滾動畫面不再顯示。目前,RecyclerView上方的TextView固定在屏幕上,而我的RecyclerView中的所有數據都是可滾動的。當用戶向下滾動頁面時,我希望TextView移出視線。如果您查看Instagram,當您向下滾動頁面時,圖庫頂部的所有用戶個人資料信息都會消失。我怎樣才能做到這一點?我如何以編程方式添加TextView?將TextView附加到RecyclerView
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello!" />
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="?android:attr/actionBarSize"
android:padding="@dimen/item_margin"
android:id="@+id/recycler_view"
android:clipToPadding="false">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello!" />
</android.support.v7.widget.RecyclerView>
試試這個方法:https://github.com/chrisbanes/cheesesquare –
[RecyclerView頁眉和頁腳(可能的重複http://stackoverflow.com/questions/26585941/recyclerview-header-and-頁腳) – starkshang
https://github.com/blipinsk/RecyclerViewHeader –