最近项目中发现了一个奇怪的问题,scrollview里面有两个recycleview,这两个recycleview 不需要滑动,只要scrollview可以滑动就行,结果在Android 6.0 以上的机型都不行。以下代码可以直接解决:
<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="wrap_content">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
如果要设置recyclerview禁止滑动,可以用以下代码
GridLayoutManager gridLayout = new GridLayoutManager(this, 2) {
@Override
public boolean canScrollVertically() {
return false;
}
};
LinearLayoutManager linearLayout = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL, false) {
@Override
public boolean canScrollVertically() {
return false;
}
};
mGridRecyclerview.setLayoutManager(gridLayout);
mLineRecyclerview.setLayoutManager(linearLayout);