嵌套滚动视图中的recyclerview没有出现褶皱

问题描述 投票:0回答:2

我在recyclerview中有一个nestedScrollView,并且我已经停止了recyclerview的滚动以允许nestedScrollView滚动所有页面,但是nestedScrollView无法正常工作。

我已经将nestedScrollingEnabledrecyclerview设置为false

我试图在recyclerview下添加一个隐藏视图,但它已显示在recyclerview底部项目的顶部

我的布局xml文件代码为:

<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android">

<data>
    <variable
        name="viewModel"
        type="com.accad.accadgame.viewmodels.profile.ProfileViewModel" />
</data>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/circleImageView"
            android:layout_width="75dp"
            android:layout_height="0dp"
            android:layout_marginStart="@dimen/default_dim"
            android:layout_marginTop="@dimen/default_xxdim"
            android:layout_marginEnd="@dimen/default_dim"
            android:src="@drawable/profile"
            app:layout_constraintDimensionRatio="h,1:1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/profile_name"
            style="@style/HeadlineTextViewActiveStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/default_dim"
            android:layout_marginStart="@dimen/default_dim"
            android:layout_marginEnd="@dimen/default_dim"
            android:text="@{viewModel.profileName}"
            app:layout_constraintEnd_toEndOf="@+id/circleImageView"
            app:layout_constraintStart_toStartOf="@+id/circleImageView"
            app:layout_constraintTop_toBottomOf="@+id/circleImageView"
            tools:text="@tools:sample/lorem" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/profile_details_list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginTop="@dimen/default_xxdim"
            android:clipToPadding="false"
            android:paddingBottom="@dimen/default_dim"
            android:paddingStart="@dimen/default_dim"
            android:nestedScrollingEnabled="false"
            app:layout_constraintBottom_toBottomOf="parent"
            android:focusable="false"
            app:layout_constraintTop_toBottomOf="@id/profile_name"
            />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

android android-recyclerview android-nestedscrollview
2个回答
0
投票

经过多次尝试,我找到了解决方法

recyclerView的高度更改为wrap_content而不是match_parent0dp,因此recyclerView如下所示:

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/profile_details_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/default_xxdim"
        android:clipToPadding="false"
        android:paddingBottom="@dimen/default_dim"
        android:paddingStart="@dimen/default_dim"
        android:nestedScrollingEnabled="false"
        app:layout_constraintBottom_toBottomOf="parent"
        android:focusable="false"
        app:layout_constraintTop_toBottomOf="@id/profile_name"
        />

-1
投票

将静态内容作为RV中的第一项。

我知道这听起来可能很糟糕,但请相信我,这比嵌套的RecyclerView好得多。

这将解决嵌套RV的回收,滚动,拖动和许多其他问题。

© www.soinside.com 2019 - 2024. All rights reserved.