如何将视图和回收器视图放置在同一屏幕中



我正在尝试将recyclerView与具有textView的屏幕(Fragment(放在一起。

我试图添加到的片段的.xml文件:

<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"
tools:context=".ui.ways.WaysFragment">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/ways_quote"
android:layout_marginTop="@dimen/card_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textSize="18sp"
android:layout_marginBottom="10dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:listitem="@layout/custom_ways_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

我会尝试用代码和文字来描述我试图做的事情的外观(结果(,而不是图片,我认为这样会很容易理解

一开始我添加了textView,并将recyclerView放在它下面。我得到的结果(出现在我的测试设备上(看起来像:

Layout:
....
TextView:
....
ScrollView:
....
and the contents of my recyclerView

我的意思是,textView不会滚动,但recyclerView会滚动。

接下来我将textViewrecyclerView放在单个scrollView中。但是textView与recyclerView是分开滚动的,就好像textView和recyclerView在不同的滚动视图中一样。我得到的结果(出现在我的测试设备上(看起来像:

Layout:
....
ScrollView:
....
TextView:
....
ScrollView:
....
and the contents of my recyclerView

我想要的外观是

Layout:
....
ScrollView:
....

TextView:
....
Contents of my recyclerView:
....

我发现我把这个问题命名错了,应该是"如何使用kotlin将收割台放入回收站";。

为此,我为标头创建了一个新的布局,并创建了适配器。

然后我使用ConcatAdapter将头的适配器和recycleview添加到一起。

我遵循了这篇关于媒介的教程。

最新更新