簡體   English   中英

NestedScrollView中的RecyclerView - 不需要的滾動開始

[英]RecyclerView inside NestedScrollView - unwanted scroll to begin

我的布局包括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>

在java代碼中,這是RecyclerView的初始化方式:

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

一些回收商查看項目包含微調器。 問題:選擇微調器值后,回收器視圖會自動滾動開始。 我不明白為什么,如何預防呢? 選定事件上的微調器僅更新綁定到適配器的集合。 每次發生時,recyclerview都會滾動開始。

你能嘗試在你的scrollview ConstraintLayout的第一個元素中添加android:descendantFocusability =“blocksDescendants”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM