2017-08-26 53 views
0

我正在構建一個社交應用程序,並且有一個查看用戶個人資料(如Instagram)的活動。Android - Recycleview Inside Scrollview

我基本上希望能夠從ScrollView正常滾動到RecyclerView,反之亦然。 因此,例如,如果用戶從RecyclerView的底部強力滑動,我希望它將他帶到ScrollView的頂部。我正在考慮以下解決方案(但不知道如何去做):使RecyclerView的高度「展開」,這樣它將包含所有項目但沒有滾動條,這樣ScrollView就可以做到這一點。

我的佈局是這樣的:

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

    <android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

    <!-- FIRST REGION THIS IS SET PRGRAMATICALLY TO TAKE UP WHOLE SCREEN--> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

       <ImageView> <Textview> <Bla> <Bla> 

     </RelativeLayout> 

    <!-- SECOND REGION ALSO SET TO TAKE UP ALL SCREEN PROGRAMATICALLY--> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

     <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="vertical" 
      /> 

     </RelativeLayout> 

    </LinearLayout> 

    </android.support.v4.widget.NestedScrollView> 

</RelativeLayout> 

截圖: First Region Second Region

回答

0

使用本mRecyclerView.setNestedScrollingEnabled(false);