简体   繁体   English

如何在约束布局的recyclerview底部添加按钮?

[英]How to add button in the bottom of recyclerview in constraint layout?

I am new to constraint layout and I am trying to add my button below recyclerview, but I am not able to do that in constraint layout.我是约束布局的新手,我试图在 recyclerview 下方添加我的按钮,但我无法在约束布局中做到这一点。 How I can achieve this functionality in constraint layout.我如何在约束布局中实现此功能。

I am also share image for better understanding.我也分享图像以便更好地理解。

Try this sample code:试试这个示例代码:

<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>

The important point is that the ListView 's height must be 0 and app:layout_constraintBottom_toTopOf="@+id/button" and app:layout_constraintTop_toTopOf="parent" .重要的一点是ListView的高度必须是0app:layout_constraintBottom_toTopOf="@+id/button"app:layout_constraintTop_toTopOf="parent"

Try something like this:尝试这样的事情:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM