简体   繁体   English

NestedScrollView中的RecyclerView - 不需要的滚动开始

[英]RecyclerView inside NestedScrollView - unwanted scroll to begin

My layout includes RecyclerView inside NestedScrollView, like this: 我的布局包括NestedScrollView中的RecyclerView,如下所示:

 <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
   <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:id="@+id/scrollView2"
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_marginBottom="@dimen/default_margin"
                    android:layout_marginLeft="@dimen/default_margin"
                    android:layout_marginRight="@dimen/default_margin"
                    android:layout_marginTop="@dimen/default_margin"
                    android:maxLength="32"
                    app:layout_constraintBottom_toTopOf="@+id/linear2"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintVertical_bias="0.0">

            <androidx.constraintlayout.widget.ConstraintLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

              ...some controls unrelated
               <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/parametersList"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:fadeScrollbars="false"
                    android:paddingTop="8dp"
                    android:paddingBottom="32dp"
                    android:scrollbars="vertical"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="0.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/add_event_phone_number"/>

  </androidx.constraintlayout.widget.ConstraintLayout>
        </androidx.core.widget.NestedScrollView>

        <LinearLayout
            android:id="@+id/linear2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/default_margin"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_marginRight="@dimen/default_margin"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent">

            <Button
                android:id="@+id/add_event_confirm_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:layout_weight="1"
                android:background="@android:color/holo_green_dark"
                android:elevation="0dp"
                android:text="@string/button_confirm"
                android:textColor="@android:color/white"/>

            <Button
                android:id="@+id/add_event_cancel_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_weight="1"
                android:background="@color/cardview_dark_background"
                android:text="@string/button_cancel"
                android:textColor="@android:color/white"/>
        </LinearLayout>



    </androidx.constraintlayout.widget.ConstraintLayout>

In java code, this is how RecyclerView is initialized: 在java代码中,这是RecyclerView的初始化方式:

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(parametersAdapter);
recyclerView.parametersList.setNestedScrollingEnabled(false);

Some recycler view items contain spinners. 一些回收商查看项目包含微调器。 Problem: when spinner value selected, recycler view automatically scrolls to begin. 问题:选择微调器值后,回收器视图会自动滚动开始。 I don't understand why, how to prevent it? 我不明白为什么,如何预防呢? Spinner's on selected event only updates collection bound to adapter. 选定事件上的微调器仅更新绑定到适配器的集合。 Every time it happens, recyclerview scrolls to begin. 每次发生时,recyclerview都会滚动开始。

你能尝试在你的scrollview ConstraintLayout的第一个元素中添加android:descendantFocusability =“blocksDescendants”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NestedScrollView内的RecyclerView比RecyclerView滚动得更快 - RecyclerView inside NestedScrollView scroll faster than RecyclerView 检查nestedscrollview中的recyclelerview滚动状态 - Check recyclerview scroll state inside nestedscrollview LinearLayout 和 NestedScrollView 中的 RecyclerView - 如何滚动到某个位置的项目顶部? - RecyclerView inside LinearLayout and NestedScrollView - How to scroll to top of item on a certain position? NestedScrollView里面没有使用Recyclerview - NestedScrollView not fling with Recyclerview inside RecyclerView 不在 NestedScrollView 内滚动 - RecyclerView not scrolling inside NestedScrollView NestedScrollView 内的 RecyclerView 问题 - RecyclerView inside NestedScrollView issue 在nestedscrollview的recyclerview内部的recyclerview的notifyDataChanged上,外部recyclerview滚动到顶部 - On notifyDataChanged of recyclerview inside a recyclerview in a nestedscrollview the outer recyclerview scrolls to top 使用NestedScrollView中的Multiple Recyclerview不会发生回收 - View Recycling not happens with Multiple Recyclerview inside NestedScrollView 嵌套滚动视图中的 recyclerview addOnScrollListener (endless scrolllistener) - recyclerview inside nestedscrollview addOnScrollListener (endless scrolllistener) 如何在 NestedScrollView 中限制 RecyclerView 的高度 - How to limit the height of a RecyclerView inside a NestedScrollView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM