2015-12-26 49 views
0

我試圖(從https://mzgreen.github.io/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling(part2)的靈感)隱藏一個視圖當我向上滾動並在滾動顯示時顯示它。RecycleView如何隱藏滾動頂部視圖(不是工具欄)上的頂視圖

但它似乎沒有很好的工作。當我向上滾動TextView的時候會消失,但是從頂部到列表視圖的開始留下一個空白區域。 (在下面的情況下我的TextView的使用.setTransalteX(DY)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/test" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

我應該使用什麼樣的佈局歸檔相同的,而不是離開時,我向上滾動的空白區域,但該列表取空間的文字視圖?

(這樣做的應用程序的示例是Booking.com的結果列表) (它不會出現向下滾動時,但那很好..它的事實,搜索過濾器向上滾動當列表向上滾動時) enter image description here enter image description here

回答

2
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:paddingTop="44dp" 
     android:cliptoPadding="false" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <TextView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/test" 
     android:layout_width="fill_parent" 
     android:layout_height="44dp" /> 
</LinearLayout> 
+0

android:paddingTop =「44dp」這不是真的動態.. 我已經試過這個。 (通過在代碼中設置填充取決於textview的大小),但它的效果與我有linearLayout(填充大小的空白空間)時的效果相同 – Johny19

+0

你想實現什麼? –

+0

如果你只是想讓textview和Recyclerview一起滾動,只需要添加textview作爲Recyclerview的第一個孩子。或者用一個簡單的方法搜索headerRecyclerView。 –

相關問題