【发布时间】:2021-08-20 00:28:36
【问题描述】:
我的 xml 代码有问题。这是我页面的截图:https://i.stack.imgur.com/M6kvA.jpg
在这张照片中,您可以看到 Text View 上面写着“Popular Tv Series”,位于回收站视图项目上方。我想将此 textView 放置在 recycler view 上方,这样它们就不会相互覆盖。这是我正在使用的两种布局的 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>
【问题讨论】:
-
你想让 textview 在回收站视图上滚动吗?
-
不不,您只想将 textView 放在回收站视图上方,当我向下滚动时,回收站视图上方的所有内容都将被删除。但是我知道如何使用协调器布局来做到这一点,我只是不知道如何将 textview 定位在 recyclerview 上方,不像现在在 recyclerview 中那样
标签: java android xml android-recyclerview android-constraintlayout