【发布时间】:2020-01-07 06:18:03
【问题描述】:
我正在尝试制作一个看起来像这样的Dialog
这里,橙色矩形中的元素是Dialog 的固定页眉和页脚部分。蓝色矩形内的元素根据要显示的内容动态放置。
这是它的 XML。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/header_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<!-- some views -->
</LinearLayout>
<LinearLayout
android:id="@+id/body_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@id/header_section"
app:layout_constraintBottom_toTopOf="@id/footer_section"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
</LinearLayout>
<LinearLayout
android:id="@+id/footer_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<!-- some views -->
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
当我将其他视图放置在蓝色区域内时它工作正常,但是当 RecyclerView 放置在其中并动态添加项目时,它会变大并与页眉部分中的文本重叠并推动页脚部分到底部。如何让RecyclerView 只覆盖蓝色区域?
【问题讨论】:
-
为什么你需要在 ConstraintLayout 中使用线性布局?可以通过单个约束布局来实现!
-
希望对您有所帮助:stackoverflow.com/q/33560276
-
@SantanuSur 我将不同的部分放在
LinearLayout中只是为了使代码看起来干净并保持其所有内容受到约束,而不必对页眉和页脚部分中的每个View应用约束。 -
@ViralPatel 谢谢,但您分享的链接没有回答问题。
标签: android xml android-recyclerview