【发布时间】:2020-09-02 18:50:57
【问题描述】:
我是约束布局的新手,我正在尝试在 recyclerview 下方添加我的按钮,但我无法在约束布局中执行此操作。 如何在约束布局中实现此功能。
【问题讨论】:
标签: android android-constraintlayout
我是约束布局的新手,我正在尝试在 recyclerview 下方添加我的按钮,但我无法在约束布局中执行此操作。 如何在约束布局中实现此功能。
【问题讨论】:
标签: android android-constraintlayout
试试这个示例代码:
<androidx.constraintlayout.widget.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">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
重要的是ListView的高度必须是0和app:layout_constraintBottom_toTopOf="@+id/button"和app:layout_constraintTop_toTopOf="parent"。
【讨论】:
试试这样的:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/myButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
【讨论】: