将框架布局放置在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我想更好地控制它的位置。

Zain

您可以将高度设为匹配约束(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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将溢出菜单放置在工具栏下方而不是溢出菜单与应用栏重叠

来自分类Dev

如何在Android工具栏下方启动抽屉布局?

来自分类Dev

如何消除工具栏和下方布局之间的间隙

来自分类Dev

RecyclerView在工具栏下方

来自分类Dev

工具栏下方的白条

来自分类Dev

如何将导航抽屉放在工具栏下方?

来自分类Dev

底部工具栏布局

来自分类Dev

将textAngular工具栏放置在textEditor的底部

来自分类Dev

使用PyQt将QWidgets放置在工具栏中

来自分类Dev

如何将布局背景合并到工具栏

来自分类Dev

Android将底部工具栏移到布局顶部

来自分类Dev

将工具栏移到相对布局的顶部

来自分类Dev

使用Swing将工具栏添加到框架

来自分类Dev

在协调器布局中隐藏在工具栏下方的视图

来自分类Dev

工具栏下方的AppBarLayout滚动内容

来自分类Dev

在工具栏下方添加片段

来自分类Dev

如何使DrawerLayout显示在工具栏下方?

来自分类Dev

在工具栏下方添加片段

来自分类Dev

工具栏在TabLayout上放置阴影

来自分类Dev

在工具栏中添加布局

来自分类Dev

工具栏中的布局问题

来自分类Dev

工具栏重叠相对布局

来自分类Dev

工具栏覆盖相对布局

来自分类Dev

如何将视图元素粘贴在Android中的collapsingtoolbarlayout工具栏下方?

来自分类Dev

将TabLayout固定到工具栏Scrollview的顶部和下方

来自分类Dev

工具栏在状态栏下方重叠

来自分类Dev

CoordinatorLayout中工具栏下方的进度栏

来自分类Dev

UICollectionView框架工具栏错误

来自分类Dev

将KENDOUI工具栏与网格工具栏集成