2015-09-04 181 views
5

所以我有一個垂直ScrollView內的水平RecyclerView。我的佈局中的所有內容都可以很好地顯示出來,並且可以順暢地滾動到所需的方向。垂直水平RecyclerView ScrollView

我唯一的問題是,RecyclerView低於ScrollView中的一些其他內容,當RecyclerView部分可見時,它將在啓動時將RecyclerView的底部與屏幕底部對齊。這意味着RecyclerView上方的內容被推出屏幕。

有誰知道爲什麼會發生這種情況,我該如何解決?

這是一個簡單的佈局,可以完成我剛剛描述的內容。你甚至不需要填充RecyclerView,它仍然會這樣做。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="500dp" 
      android:background="#fff"/> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:background="#000"/> 

    </LinearLayout> 

</ScrollView> 
+0

檢查這個https://github.com/lucasr/twoway-view/。 – Raghunandan

+0

從我所瞭解的TwoWayView來看,它與我的問題並不真正相關,但無論如何感謝。 –

回答

6

原來,這個問題據報道,谷歌在這裏Issue - 81854

據谷歌稱,它正在按預期。問題在於RecyclerView的focusableInTouchMode設置爲true。爲了解決這個問題,我設置focusableInTouchModefocusable在ScrollView的最頂層視圖上爲true。

下面是我在原來的問題提供的代碼示例修復:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="500dp" 
      android:background="#fff" 
      android:focusableInTouchMode="true" 
      android:focusable="true"/> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:background="#000"/> 

    </LinearLayout> 

</ScrollView> 
+0

你說過在ScrollView的最頂層視圖上將'focusableInTouchMode'和'focusable'設置爲true。但在代碼中,我看到了不同的東西。請澄清。 –

+0

@Parsi對不起。由於ScrollView只能有一個孩子,我的意思是ScrollView孩子的最頂層視圖。 –

+0

那我沒那個意思。謝謝。沒有提及 :) –

相關問題