android - 将框架布局放置在 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
解决方案
您可以将高度设置为匹配约束(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>
推荐阅读
- c++ - C++ 的编译错误:“架构 x86_64 的未定义符号”
- php - 如何获得具有相同变化的所有产品 - woocommerce
- salesforce - 从 SocialStudio API 检索轮播列/指标的问题
- java - 使用前台服务时地理围栏未触发
- android - 如何在 RecyclerView Android 中更快地加载项目
- javascript - 如果 NodeJS 服务器上不断出现请求,NodeJS 什么时候有时间进入下一个事件循环周期?
- c++ - c++ - 没有匹配的调用函数
- go - 如何为 godotenv.Load() .env 文件使用动态位置?
- android - 如何在android中将recyclerview项目集中在horizontalscrollview中?
- node.js - 在 firebase 的公共目录中托管静态内容