5

Tôi đã tạo bố cục có hai RecyclerViews. Một cuộn cuộn theo chiều ngang trong khi các cuộn khác theo chiều dọc. Tôi có thể cuộn một cách chính xác bên trong mỗi RecyclerView nhưng toàn bộ trang sẽ không cuộn, tức là đầu RecyclerView vẫn ở đầu và cuối cùng ở dưới cùng như cả hai đều cố định ở vị trí.Scolling với nhiều RecyclerViews trong Layout

Tiếp theo là bố trí xml của tôi:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <EditText 
      android:id="@+id/search" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:hint="Search Dramas" 
      android:textSize="16sp" 
      android:paddingLeft="10dp" 
      android:gravity="center" 
      android:textColor="@color/dark_grey" 
      android:textColorHint="@color/dark_grey" 
      android:background="@drawable/border_bottom"/> 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/border_bottom_background_black" 
      android:textColor="@color/white" 
      android:padding="10dp" 
      android:text="Most Watched"/> 

     <!-- A RecyclerView to display horizontal list --> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/featured" 
      android:scrollbars="none" 
      android:layout_width="fill_parent" 
      android:layout_height="240dp" 
      android:paddingLeft="0dp" 
      android:paddingRight="15dp" 
      android:paddingTop="15dp" 
      android:paddingBottom="25dp" 
      android:background="@color/black"/> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/border_bottom_backgroundless" 
      android:textColor="@color/dark_grey" 
      android:padding="10dp" 
      android:text="All Dramas"/> 

     <!-- A RecyclerView to display vertical list --> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/pick_item" 
      android:scrollbars="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent"/> 


</LinearLayout> 

How activity looks

Trả lời

6

Tôi đã có thể giải quyết vấn đề bằng cách đặt mọi thứ bên trong ScrollView và sau đó đặt chiều cao của RecyclerView theo chiều dọc theo cách thủ công/lập trình.

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

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

      <EditText 
       android:id="@+id/search" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:hint="Search Dramas" 
       android:textSize="16sp" 
       android:paddingLeft="10dp" 
       android:gravity="center" 
       android:textColor="@color/dark_grey" 
       android:textColorHint="@color/dark_grey" 
       android:background="@drawable/border_bottom"/> 


      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/border_bottom_background_black" 
       android:textColor="@color/white" 
       android:padding="10dp" 
       android:text="Most Watched"/> 

      <!-- A RecyclerView to display horizontal list --> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/featured" 
       android:scrollbars="none" 
       android:layout_width="fill_parent" 
       android:layout_height="240dp" 
       android:paddingLeft="0dp" 
       android:paddingRight="15dp" 
       android:paddingTop="15dp" 
       android:paddingBottom="25dp" 
       android:background="@color/black"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/border_bottom_backgroundless" 
       android:textColor="@color/dark_grey" 
       android:padding="10dp" 
       android:text="All Dramas"/> 

      <!-- A RecyclerView to display list --> 
      <android.support.v7.widget.RecyclerView 
       android:id="@+id/pick_item" 
       android:paddingBottom="20dp" 
       android:scrollbars="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent" 
       android:minHeight="840dp"/> 


    </LinearLayout> 
</ScrollView> 

Thiết chiều cao RecyclerView của lập trình:

LinearLayout.LayoutParams params = new  
    LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
    ViewGroup.LayoutParams.WRAP_CONTENT); 
// calculate height of RecyclerView based on child count 
params.height=1150; 
// set height of RecyclerView 
recyclerView.setLayoutParams(params); 
+0

Bạn đang mất tối ưu hóa RecycleVew, phải không? Nói cách khác, RecycleView sẽ không tái chế các khung nhìn. –

3

RecyclerView chỉ đạt được (vẫn còn hạn chế) hỗ trợ cho di chuyển lồng nhau trong phiên bản 22.2.0 - đề nghị đầu tiên của tôi sẽ phải cố gắng đó.

Quan điểm duy nhất hỗ trợ hoàn toàn di chuyển lồng nhau là NestedScrollView (bạn có thể thấy điều này bằng cách ghi nhận rằng nó thực hiện cả hai NestedScrollingChildNestedScrollingParent) và đã được bổ sung trong phiên bản Hỗ trợ v4 22.1.0 (hơi được cải thiện trong 22.2.0). Nếu bạn chỉ có một mặt hàng ngang trên cùng RecyclerView ngang hàng theo chiều dọc RecyclerView, thay vào đó bạn có thể thay thế bằng NestedScrollView có chứa LinearLayout với số ngang RecyclerView ngang theo sau là RecyclerView theo chiều dọc của bạn.

+0

tôi sử dụng ba điểm tái chế trong một bố trí và trong một lần xem cuộn. của tôi recycler xem các mục trong lần tái chế 2 xem được cuộn. và tôi muốn hiển thị tất cả các mục mà không cần cuộn. nhưng đã thành công với NestedScrollView. thanks –