Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
524 views
in Technique[技术] by (71.8m points)

(android) How to place a view below other views in constraint layout

enter image description here

This picture is state of layout

I want to place the RecyclerView below the Button

However, as you can see, even with layout_constraintTop_toBottomOf, the RecyclerView is not placed

under the Button

There is a condition, the size of the RecyclerView must be math_parent.

This is because you are using a nested recycler view and you are dynamically adding items, otherwise

the last nested recycler view's item will be cut off and not visible when adding dynamically..

If I set the height of a view to match_parent in the constraint layout, is there any way to place it

below other views?

This is XML file.

activity_write_routine.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".data.DailyRecordDetailActivity">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Theme.AppBarOverlay"
        app:elevation="0dp">
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <TextView
                    android:id="@+id/body_part_detail_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="P A R T"
                    android:textColor="@color/white"
                    android:textAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                    android:layout_centerHorizontal="true"/>
            </RelativeLayout>
        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
        <Button
            android:id="@+id/add_routine"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="A D D"
            android:backgroundTint="@color/light_green"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintRight_toRightOf="parent"/>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/routine_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            app:layout_constraintTop_toBottomOf="@+id/add_routine"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
question from:https://stackoverflow.com/questions/65851798/android-how-to-place-a-view-below-other-views-in-constraint-layout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

change the height to 0dp, and constraint the bottom of recyclerview to parent

<androidx.recyclerview.widget.RecyclerView
      android:id="@+id/routine_recyclerview"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:scrollbars="vertical"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintTop_toBottomOf="@+id/add_routine"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...