The order confirmation page was implemented in a recent project. Need to use ScrollView nested RecyclerView, when the number of items in RecyclerView is relatively large, the item will only show part of the data, and not all the items selected by the user are displayed, this time we need to do a process.

Here are two solutions:

1. Replace ScrollView with the new control NestedScrollView of 5.0. NestedScrollView supports nested sliding, which can not only fill the pit with incomplete item display, but also can fill the pit with nested sliding stuck. Do not understand the children’s shoes can go to study a wave, here will not do a detailed description.

Usage: (1), the layout file ScrollView replace “android. Support. The v4. Widget. NestedScrollView”. (2), use the code set recyclerView. SetNestedScrollingEnabled (false).

2, outside the RecyclerView nested layer RelativeLayout, then add attribute android: descendantFocusability = “blocksDescendants”.

Usage Reference:

<RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:descendantFocusability="blocksDescendants">
     
        <android.support.v7.widget.RecyclerView
             android:id="@+id/recyclerView"
             android:layout_width="match_parent"
             android:layout_height="match_parent"  
             android:overScrollMode="never"/>
             
</RelativeLayout>
Copy the code

Speaking of which we’ll familiar with android: descendantFocusability = “blocksDescendants” attribute:

This property defines the relationship between the ViewGroup and its child controls when a view gets focus.

It has a total of three attribute values, which are:

BeforeDescendants: viewGroup gets focus before subclass controls;

AfterDescendants: viewGroup gets focus only when subclass controls don’t need it;

BlocksDescendants: viewGroup overrides subclass controls to get focus directly.

That’s all for the two schemes.


The following is our personal public account (LongXuanzhigu). Our posts will be synchronized to this account, which is convenient for exchanging and learning Android knowledge and sharing personal hobbies. If you have any questions, please leave a message: