ScrollView + RecyclerView出现的问题

1、嵌套滑动冲突,导致滑动时会出现卡顿的现象:

解决办法:重写LayoutManager的canScrollVertically方法或者canScrollHorizontally方法就返回false就行了:

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

2、ScrollView当中嵌套RecyclerView ,RecyclerView 会自动滚动到顶部

解决办法:在代码里面 让处于ScrollView顶端的某个控件获得焦点即可

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

3、RecyclerView内容显示不完全:

解决办法:在RecyclerView外嵌套一层RelativeLayout,网上有说还要给RelativeLayout加上android:descendantFocusability="blocksDescendants"  这个属性,但我试过之后发现不加也可以。

<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>

猜你喜欢

转载自blog.csdn.net/tang_jian_1228/article/details/80229466