nestedScrollView内的RecyclerView无法平滑滚动

时间:2019-07-17 09:43:59

标签: android android-recyclerview android-nestedscrollview

我有两个布局,父布局带有nestedscrollview,子布局有recylerview。

  

父级布局

<androidx.core.widget.NestedScrollView
        android:id="@+id/sv_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:background="@drawable/bg_shimmer_forms_loading"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:padding="@dimen/padding_8dp">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="true"
            android:paddingStart="@dimen/margin_8dp"
            android:paddingEnd="@dimen/margin_8dp">


        <LinearLayout
                android:id="@+id/ll_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:animateLayoutChanges="true"
                android:orientation="vertical"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:clickable="true">

        </LinearLayout>
                <Space
                android:layout_width="wrap_content"
                android:layout_height="@dimen/dimen_500dp"
                android:background="@color/black"
                app:layout_constraintStart_toStartOf="@id/ll_container"
                app:layout_constraintEnd_toEndOf="@id/ll_container"
                app:layout_constraintTop_toBottomOf="@id/ll_container"/>

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

子布局

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/grey_300"
    android:minWidth="150dp"
    android:paddingStart="@dimen/margin_8dp"
    android:paddingEnd="@dimen/margin_8dp"
    android:paddingBottom="@dimen/padding_12dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:id="@+id/fe_running_notes_tv_label"
        style="@style/tv_style_label_header"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text='@{viewModel.title==null||viewModel.title.equalsIgnoreCase("")?"":Html.fromHtml(viewModel.title)}'
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/fe_running_notes_et"
        style="@style/tv_style_dark_medium"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_all_border"
        android:gravity="top"
        android:hint="@string/hint_add_notes_here"
        android:minHeight="@dimen/minWidth_150dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fe_running_notes_tv_label" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/fe_running_notes_btn_save"
        style="@style/button_style_value"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/height_45dp"
        android:layout_marginTop="@dimen/margin_16dp"
        android:background="@color/blue_900"
        android:text="@string/label_save"
        android:textAllCaps="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fe_running_notes_et" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/fe_running_notes_btn_clear"
        style="@style/button_style_value"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/height_45dp"
        android:layout_marginEnd="@dimen/margin_8dp"
        android:background="@color/white"
        android:text="@string/label_clear"
        android:textAllCaps="false"
        android:textColor="@color/grey_600"
        app:layout_constraintBottom_toBottomOf="@id/fe_running_notes_btn_save"
        app:layout_constraintEnd_toStartOf="@id/fe_running_notes_btn_save"
        app:layout_constraintTop_toTopOf="@id/fe_running_notes_btn_save" />

    <View

        android:id="@+id/fe_running_notes_line_divider"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_marginTop="@dimen/margin_16dp"
        android:background="@color/grey_500"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fe_running_notes_btn_save">

    </View>


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/fe_running_notes_recycler_rv"
        android:layout_width="0dp"
        android:layout_height="@dimen/width_200dp"
        android:layout_marginTop="@dimen/margin_8dp"
        android:scrollbars="vertical"
        android:visibility="gone"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fe_running_notes_line_divider"
        tools:visibility="visible" />

</androidx.constraintlayout.widget.ConstraintLayout>

我几乎尝试了所有可能的方法,但无法平滑滚动我的recyclerview内容,尽管有时它仍可滚动,但大多数时候却没有。

我尝试了以下代码

ViewCompat.setNestedScrollingEnabled(mBinding.feRunningNotesRecyclerRv,false);

没有什么让我找到解决方案的,请帮助我

0 个答案:

没有答案