【问题标题】:How to add button in the bottom of recyclerview in constraint layout?如何在约束布局的recyclerview底部添加按钮?
【发布时间】:2020-09-02 18:50:57
【问题描述】:

我是约束布局的新手,我正在尝试在 recyclerview 下方添加我的按钮,但我无法在约束布局中执行此操作。 如何在约束布局中实现此功能。

I am also share image for better understanding.

【问题讨论】:

    标签: android android-constraintlayout


    【解决方案1】:

    试试这个示例代码:

    <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的高度必须是0app:layout_constraintBottom_toTopOf="@+id/button"app:layout_constraintTop_toTopOf="parent"

    【讨论】:

    【解决方案2】:

    试试这样的:

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

    【讨论】:

      猜你喜欢
      • 2019-02-21
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 2015-11-12
      相关资源
      最近更新 更多