android - 为什么单个片段在一个活动中占据整个屏幕,而其他视图使用约束布局?
问题描述
我的主要活动中有两个框架布局,在运行时将被两个片段替换。我正在使用约束布局来对齐它们。一个特定的 Fragment 占据了 id为 recentsfragment 的framelayout正在替换整个屏幕,并且没有给其他 framelayout 任何位置。
当我单独显示带有片段的框架布局时,视图完全符合预期。
activity_main.xml
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/recentsfragment"
android:layout_width="395dp"
android:layout_height="325dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.618"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view"></FrameLayout>
<view
android:id="@+id/view"
class="android.widget.Button"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="@android:color/darker_gray"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="-51dp" />
<FrameLayout
android:id="@+id/allnotesfragment"
android:layout_width="395dp"
android:layout_height="327dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></FrameLayout>
我为他们尝试了不同的对齐方式,但没有运气。我特别想使用约束布局。任何帮助表示赞赏。谢谢。
解决方案
你只需要改变你的两个 FrameLayout0dp
就像android:layout_height="0dp"
.
推荐阅读
- python - 用 beautifulsoup 刮掉结果中不存在的
- intellij-idea - “查看参数信息”功能在 InteliJ IDEA 中不起作用
- api - Pact:测试 API (JVM) 的最小示例
- c - 打包原始数据中的有效类型
- javascript - 如何在Javascript中使用两个字段进行分组
- html - 图像没有显示在网页中,即使它是单独打开的
- javascript - 图片不存在时不显示下一个/图片组件
- next.js - Next.js 如何处理调度函数?
- git - npm / git fails with: refusing to work with credential missing host field
- postgresql - 将 Postgres 从 11 升级到 12/13/14 后查询失败