【发布时间】:2021-10-28 16:37:35
【问题描述】:
我正在开发一个 Android (Java) 应用程序。我有一个片段,上面有一个段落,下面是一个RecyclerView。当我启动应用程序并加载屏幕时,内容会滚动,以便顶部段落完全超出屏幕,并且RecyclerView 是唯一可见的内容。
按照这个解决方案:Recycler View automatically scrolls to inner recycler view on first load 我尝试添加
android:descendantFocusability="blocksDescendants"
和
focusable="false"
到回收站视图,但它们都不起作用。
这是片段的 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a welcome text"
android:textSize="15sp"
android:lineSpacingExtra="5dp"
android:paddingTop="10dp"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingBottom="16dp"
android:textColor="#000000"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/buttonOptions">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/pathsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:descendantFocusability="blocksDescendants"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
如何解决页面不自动滚动的问题?
【问题讨论】:
-
这可能是因为滚动视图环绕着回收器视图。当一个可滚动视图包装另一个可滚动视图时,我看到了与 android 类似的问题。您是否尝试过删除滚动视图?
-
你想要这样的东西:youtu.be/nUnPoxo_ZG4?
标签: android android-recyclerview scroll scrollview android-scrollview