【发布时间】:2022-01-08 21:31:07
【问题描述】:
我有一个ConstraintLayout,我想在屏幕底部显示一个按钮。屏幕的主要区域是RecyclerView,以防万一。
无论如何,我想在按钮上方有一个水平线视图。
我尝试了以下方法:
<?xml version="1.0" encoding="utf-8"?>
<ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="Some text here"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
app:layout_constraintTop_toBottomOf="@id/text"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginStart="16dp"
android:background="@color/red_color"
app:layout_constraintBottom_toBottomOf="@id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/recycler"
app:layout_constraintVertical_bias="0.887" />
<Button
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Click Here"
/>
</ConstraintLayout>
但虚拟视图没有显示在按钮上方。
我能做些什么来解决这个问题?
【问题讨论】:
-
如果可能,请提供您想做什么的图片
-
@KaranMehta:我只想要屏幕底部按钮上方的红色水平线
-
我可以建议如何使用线性布局或相对布局
-
@KaranMehta:我需要使用 ConstraintLayout。
标签: android android-layout android-constraintlayout