Java 如何在recyclerView上定位文本视图?
我的xml代码有一个问题。以下是我的页面截图: 在这张照片中,你可以看到Java 如何在recyclerView上定位文本视图?,java,android,xml,android-recyclerview,android-constraintlayout,Java,Android,Xml,Android Recyclerview,Android Constraintlayout,我的xml代码有一个问题。以下是我的页面截图: 在这张照片中,你可以看到文本视图,上面写着“热门电视剧”,它位于回收商视图项目上方。我想将此文本视图置于回收器视图上方,这样它们就不会相互覆盖。下面是我正在使用的两种布局的xml代码。我尝试过使用约束,但似乎textView已经修复。谢谢 fragment_search.xml <?xml version="1.0" encoding="utf-8"?> <androidx.constrai
文本视图
,上面写着“热门电视剧”,它位于回收商视图项目上方。我想将此文本视图置于回收器视图上方
,这样它们就不会相互覆盖。下面是我正在使用的两种布局的xml代码。我尝试过使用约束,但似乎textView
已经修复。谢谢
fragment_search.xml
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.SearchFragment.SearchFragment">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/edit_text_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_margin="8dp"
app:endIconMode="clear_text"
app:startIconDrawable="@drawable/ic_search_bottomnav"
android:hint="@string/searchbar_hint"
app:boxStrokeColor="@color/dark_red"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/light_gray"
android:layout_marginTop="20dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintTop_toBottomOf="@+id/edit_text_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_fragment_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_recommended"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/text_view_recommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"
android:layout_margin="10dp"
android:text="@string/searchFragment_mostPopular"
android:textStyle="bold"
android:textColor="@color/white"
android:textSize="23sp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
item_fragmentsearch_popular.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/movie_image"
android:layout_width="150dp"
android:layout_height="250dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:scaleType="fitXY"
android:layout_margin="5dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
1-在recyclerview之前声明textview。 将高度=0dp分配给recyclerview,contraints将自动为其分配高度
其他注意事项:如果为任何视图指定匹配父视图宽度,则无需写入“开始到开始”和“结束到结束”控件。是否希望textview可在“回收器”视图上滚动?不,不,您只需将textview定位在“回收器”视图上方,当我向下滚动时,所有位于“回收器”视图上方的内容都将被删除。但我知道如何使用协调器布局,我只是不知道如何将文本视图定位在recyclerview上方,而不像现在的RecyclerViewHanks内部。你真的帮了我。不客气,快乐。