android - 框架布局在 ConstraintLayout 内未正确定位
问题描述
我已经放置了一个FrameLayout
内部ConstraintLayout
,我认为它受到了适当的限制。但是在应用程序中,它没有正确定位。FrameLayout
在运行时被适当的片段替换。
<?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=".ui.chapters.ChapterActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_chapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="Chapters"
app:titleTextColor="@color/White" />
<FrameLayout
android:id="@+id/chapter_fragment_container_frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="500dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.388"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_chapter"
app:layout_constraintVertical_bias="1.0" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
app:itemIconTint="@color/White"
app:itemTextColor="@color/Wheat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/chapter_bottom_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</androidx.constraintlayout.widget.ConstraintLayout>
以下是 IDE 中显示的内容:
但这是我在设备中得到的:
FrameLayout
应该放在工具栏和底部导航栏之间,应该由LinearLayout/Relative
一个完成,虽然没有尝试过..但这有什么问题。
解决方案
更改此 FrameLayout 部分,如下所示:
<FrameLayout
android:id="@+id/chapter_fragment_container_frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:minHeight="500dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.388"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar_chapter"
app:layout_constraintVertical_bias="1.0" />
它发生的原因是因为match_constraint
。如果你已经定义了约束,top, bottom, start, and end
你应该定义0dp
forheight
和width
to View。
推荐阅读
- c - 如何在函数中 malloc 数组,然后重新分配它
- python-3.x - Pygame:在文本中显示指数
- shiny - 如何浏览多个文件并通过R中的下拉菜单选择其中任何一个?
- javascript - 范围如何在 Webpack 中与 CommonJS 一起工作
- c - getenv() 的值在 strtok() 中不起作用
- python - 双星号错误:无效的语法
- python - 在 matplotlib 中使用 subplot_kw 在子图中创建极坐标投影
- bash - bash awk 似乎弄错了数字
- php - 如何通过 php 查询使用 htaccess 创建友好的 URL
- visual-studio - Visual Studio for Mac:无法添加 Web 参考