我有一个ScrollView,
,其中包含一个垂直LinearLayout.
这是一个地方,我在其中添加一些名为" Section"的视图。 "节"是LinearLayout,
,其中包含TextView
和`RecyclerView。
<ScrollView
android:id="@+id/main_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/sections_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
部分:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="@dimen/activity_starred_title_textsize" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
问题在于RecyclerView
有时不是wrap_content
。因此,它会产生两种类型的问题(取决于我尝试使用的解决方案类型I)。
它可以取消滚动(因此它与屏幕高度匹配,我无法将其向下滚动以查看其中的其他项目。)
它可以滚动嵌套。
最初的问题是它有嵌套滚动。所以我希望RecyclerViews
为简单的垂直LinearLayouts
,唯一必须具有滚动效果的是根ScrollView.
我尝试过什么?
扩展GridLayoutManager
并覆盖canScrollVertically().
方法:
public boolean canScrollVertically(){ 返回false; }
扩展RecyclerView
类并覆盖
@覆盖 public boolean onInterceptTouchEvent(MotionEvent event){ 返回false; }
@覆盖 public boolean onTouchEvent(MotionEvent event){ 返回false; }
在任何地方都可以通过NestedScrolling
停用xml
。
使用此解决方案覆盖GridLayoutManager
:SOLUTION
答案 0 :(得分:9)
请勿在{{1}}内使用RecyclerView
或ListView
。对于嵌套滚动,您应该使用ScrollView
。
NestedScrollView
就像NestedScrollView
一样,但它支持充当 新旧版本上的ScrollView
滚动父级和子级 Android版默认情况下启用嵌套滚动。
<强> SOLUTION:强>
1。使用nested
作为ScrollView
部分NestedScrollView
部分(Section
和其他RecyclerView
的容器,而不是使用Views
)。
<android.support.v4.widget.NestedScrollView
android:id="@+id/main_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/sections_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Your Section:: RecyclerView and other Views -->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
2. 。对于滚动问题,请使用setNestedScrollingEnabled(false)
RecyclerView
。
答案 1 :(得分:0)
下一步是解决方案: 1.使用NestedScrollView 2.覆盖GridLayoutManager.canScrollVertically():
public boolean canScrollVertically(){ return false; }