【发布时间】:2025-12-03 12:45:01
【问题描述】:
我有一个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。因此它会产生两种类型的问题(取决于我尝试使用的解决方案类型)。
它可以是不可滚动的(因此它与屏幕高度匹配,我无法向下滚动以查看里面的其余项目)。
可以嵌套滚动。
原来的问题是它有嵌套滚动。所以我希望RecyclerViews 与垂直LinearLayouts 一样简单,并且唯一必须具有滚动效果的是root ScrollView.
我尝试过做什么?
-
扩展
GridLayoutManager并覆盖canScrollVertically().方法:public boolean canScrollVertically(){ 返回假; }
-
扩展
RecyclerView类并覆盖@覆盖 公共布尔 onInterceptTouchEvent(MotionEvent 事件){ 返回假; }
@覆盖 公共布尔 onTouchEvent(MotionEvent 事件){ 返回假; }
在任何可能的地方通过
xml禁用NestedScrolling。使用此解决方案覆盖
GridLayoutManager:SOLUTION- 结合1-4
【问题讨论】:
-
您是否尝试在布局中将 ScrollView 替换为 NestedScrollView?
-
@Buckstabue 没有。我现在试试。 Tnx
-
@Buckstabue 有帮助!不仅如此,无论如何都要感谢!
-
类似的问题。 *.com/questions/39267532/…
标签: android android-layout android-recyclerview android-xml