Размещение макета кадра под панелью инструментов в ConstraintLayout

Я использую следующий код, чтобы разместить FrameLayout под панелью инструментов.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    tools:context = ".Dashboard">

    <androidx.appcompat.widget.Toolbar
        android:id = "@+id/toolbar"
        android:layout_width = "0dp"
        android:layout_height = "?attr/actionBarSize"
        android:theme = "@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"
        app:popupTheme = "@style/ThemeOverlay.AppCompat.Light">
        <RelativeLayout
            android:layout_width = "match_parent"
            android:layout_height = "match_parent">
        <TextView
            android:id = "@+id/app_title"
            android:paddingTop = "20dp"
            android:textAppearance = "@android:style/TextAppearance.Material.Large"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "App Name"
            android:textStyle = "bold"/>
      
        </RelativeLayout>
    </androidx.appcompat.widget.Toolbar>


    <FrameLayout
        android:id = "@+id/container"
        android:layout_width = "match_parent"
        android:layout_height = "match_parent"
        app:layout_behavior = "@string/appbar_scrolling_view_behavior" />

  

</androidx.constraintlayout.widget.ConstraintLayout>

Как я могу расположить FrameLayout так, чтобы он всегда был ниже toolbar, не устанавливая margin_top как actionbarsize? Я хотел бы иметь более тонкий контроль над его положением.

1
0
440
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Вы можете сделать высоту как ограничения совпадения (0dp) и ограничить ее внизу до родителя, а вверху до Toolbar

<?xml version = "1.0" encoding = "utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    xmlns:app = "http://schemas.android.com/apk/res-auto"
    xmlns:tools = "http://schemas.android.com/tools"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    tools:context = ".Dashboard">

    <androidx.appcompat.widget.Toolbar
        android:id = "@+id/toolbar"
        android:layout_width = "0dp"
        android:layout_height = "?attr/actionBarSize"
        android:theme = "@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintEnd_toEndOf = "parent"
        app:layout_constraintStart_toStartOf = "parent"
        app:layout_constraintTop_toTopOf = "parent"
        app:popupTheme = "@style/ThemeOverlay.AppCompat.Light">

        <RelativeLayout
            android:layout_width = "match_parent"
            android:layout_height = "match_parent">

            <TextView
                android:id = "@+id/app_title"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:paddingTop = "20dp"
                android:text = "App Name"
                android:textAppearance = "@android:style/TextAppearance.Material.Large"
                android:textStyle = "bold" />

        </RelativeLayout>
    </androidx.appcompat.widget.Toolbar>


    <FrameLayout
        android:id = "@+id/container"
        android:layout_width = "match_parent"
        android:layout_height = "0dp"
        app:layout_constraintBottom_toBottomOf = "parent"
        app:layout_constraintTop_toBottomOf = "@+id/toolbar" />


</androidx.constraintlayout.widget.ConstraintLayout>

Другие вопросы по теме