Android studio 如何放置回收器查看器+;一个布局中的按钮

Android studio 如何放置回收器查看器+;一个布局中的按钮,android-studio,Android Studio,我尝试了许多组合,但是如何使用约束布局,在底部使用按钮获取水平回收器 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" an

我尝试了许多组合,但是如何使用约束布局,在底部使用按钮获取水平回收器

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".FirstFragment"
    android:orientation="vertical">

   <Button
       android:id="@+id/btn_add_note"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent"/>

   <androidx.recyclerview.widget.RecyclerView
       android:id="@+id/my_recycler_view"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_gravity="bottom"
       android:orientation="horizontal"
       android:scrollbars="horizontal"
       app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="@+id/btn_add_note"
       tools:listitem="@layout/recyclerview_note">

   </androidx.recyclerview.widget.RecyclerView>

</androidx.constraintlayout.widget.ConstraintLayout>

之后,我得到一个渲染错误,表示。

java.lang.NoSuchMethodError:androidx.constraintlayout.solver.widgets.ConstraintWidget.setWrapWidth(I)V位于androidx.constraintlayout.widget.widget.constraintlayout.internalMeasureChildren(constraintlayout.java:1242)位于androidx.constraintlayout.widget.constraintlayout.onMeasure_原始版本(constraintlayout.java:1572)android.view.view.measure的androidx.constraintlayout.widget.constraintlayout.onMeasure(constraintlayout.java:-1)和android.view.view.view.view.measure的android.view.view\u Delegate.measure(view\u Delegate.java:80)和android.view.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)的androidx.view.view.view.view.view.java:24516)在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)在android.view.view.measure_Original(view.java:24552)在android.view.view_Delegate.measure(view_Delegate.java:80)在android.view.view.measure(view.java:24516)在android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)android.view.view.measure的android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)和android.view.view.view.measure的android.view.view\U Delegate.measure(view\U Delegate.java:80)和android.view.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828)的android.view.view.java:24516在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)在android.view.view.measure_Original(view.java:24552)在android.view.view_Delegate.measure(view_Delegate.java:80)在android.view.view.measure(view.java:24516)



嘿,您可能知道为什么MainActivity会抱怨上下文
val recyclerView=findViewById(R.id.my\u recycler\u视图)val adapter=NoteListAdapter(this)recyclerView.adapter=adapter recyclerView.layoutManager=LinearLayoutManager(recyclerView)
回收器视图位于片段内部。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <Button
        android:id="@+id/btn_add_note"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/my_recycler_view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent">

    </androidx.recyclerview.widget.RecyclerView>

</androidx.constraintlayout.widget.ConstraintLayout>