Problems with ScrollView + RecyclerView

1. Nested sliding conflict, resulting in a stuck phenomenon when sliding:

Solution: rewrite the canScrollVertically method or canScrollHorizontally method of LayoutManager to return false:

  recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false));
recyclerView.setLayoutManager(new LinearLayoutManager(this) {
            @Override
public boolean canScrollVertically() {
                return false;
}                                
        });

2. Nest RecyclerView in ScrollView, RecyclerView  will automatically scroll to the top

Solution: Let a control at the top of the ScrollView get the focus in the code

	educationTitle.setFocusableInTouchMode(true);
	educationTitle.requestFocus();

3. The content of RecyclerView is not displayed completely:

Solution: Nest a layer of RelativeLayout outside the RecyclerView. It is said on the Internet that the attribute android:descendantFocusability= "blocksDescendants" should be added to the RelativeLayout   , but after I tried it, I found that it is OK to not add it.

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">    <android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>        
                        

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325974295&siteId=291194637