There is a fragment with ViewPager consisting of three pages. In each page RecyclerView . Above ViewPager block with information. How to make it so that the block with the information scrolls first, and then scrolling in RecyclerView works? It cannot be placed first in the RecyclerView , since It is common to all pages in the ViewPager .

 <LinearLayout ...> <!-- вот этот блок нужно прокрутить перед RecyclerView, которые во ViewPager --> <FrameLayout ...> ... </FrameLayout> <ViewPager .../> </LinearLayout> 
  • If you need something like a header in the list, put your block with information in RecyclerView itself in this way - this is the easiest solution. Or describe in more detail what kind of interaction you want to achieve. - pavlofff
  • Cannot be placed in RecyclerView, because This is a common block for three pages in ViewPager. - Alexey Malchenko
  • TabLayout available? ViewPager size fixed for all screens? - Chaynik am
  • Maybe it makes sense to put your FrameLayout in CollapsingToolbarLayout - Andrey Kasyanov

1 answer 1

Wrap everything in NestedScrollView .....

  <android.support.v4.widget.NestedScrollView android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!--ваш контент--> </RelativeLayout> <!--укажите имя вашего пакета до кастомного пейджера--> <yuo.package.ExViewPager android:id="@+id/view_pager_recommendation" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </android.support.v4.widget.NestedScrollView> 

What would the ViewPager be of normal size after creation, specify the size of the hardcode, and if dynamically inherit from the original, and redefine the onMeasure method

 public class ExViewPager extends ViewPager { public ExViewPager(Context context) { super(context); } public ExViewPager(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = 0; for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int h = child.getMeasuredHeight(); if (h > height) height = h; } heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } 

There is a bug when scrolling "инерция" is lost when RecyclerView is touched, to get rid of this, reassign 2 methods from the LayoutManager

  GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2, LinearLayoutManager.VERTICAL, false){ @Override public boolean canScrollVertically() { return false; } @Override public boolean canScrollHorizontally() { return false; } }; 
  • It is necessary for me that at first scrolling of the block worked, and then scrolling of the list. In this example, you first need to complete the list, then just scroll the block. - Alexey Malchenko