【发布时间】:2021-01-23 03:53:30
【问题描述】:
这张照片是layout的状态
我想将RecyclerView 放在Button 下方
但是,如您所见,即使使用layout_constraintTop_toBottomOf,RecyclerView 也没有放置
Button下
有一个条件,RecyclerView的大小必须是math_parent。
这是因为您使用的是嵌套的recycler view,并且您正在动态添加项目,否则
动态添加时最后嵌套的recycler view's item会被截断,不可见..
如果我在约束布局中将视图的高度设置为 match_parent,有什么方法可以放置它
低于其他视图?
这是 XML 文件。
activity_write_routine.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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=".data.DailyRecordDetailActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.AppBarOverlay"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/body_part_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="P A R T"
android:textColor="@color/white"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<Button
android:id="@+id/add_routine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A D D"
android:backgroundTint="@color/light_green"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/routine_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="@+id/add_routine"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
【问题讨论】:
标签: android android-recyclerview android-constraintlayout