我在recyclerview
中有一个nestedScrollView
,并且我已经停止了recyclerview
的滚动以允许nestedScrollView
滚动所有页面,但是nestedScrollView
无法正常工作。
我已经将nestedScrollingEnabled
的recyclerview
设置为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>
经过多次尝试,我找到了解决方法
将recyclerView
的高度更改为wrap_content
而不是match_parent
或0dp
,因此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"
/>
将静态内容作为RV中的第一项。
我知道这听起来可能很糟糕,但请相信我,这比嵌套的RecyclerView好得多。
这将解决嵌套RV的回收,滚动,拖动和许多其他问题。