框架布局未在ConstraintLayout内正确定位

问题描述 投票:0回答:3

我在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中显示的内容:

IDE Design Preview

但是这是我在设备中得到的:

App run in Device Preview

[FrameLayout应该放置在工具栏和底部导航栏之间,应该由LinearLayout/Relative一个完成,虽然还没有尝试..但是这有什么问题。

android android-fragments android-constraintlayout android-framelayout
3个回答
2
投票

如下更改此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定义了约束,则应该为0dpheight定义width来查看。


0
投票

将framelayout的android:layout_height属性从“ match_parent”更改为“ wrap_content”


0
投票

将FrameLayout的高度更改为0dp,

<FrameLayout
        android:id="@+id/chapter_fragment_container_frameLayout"
        android:layout_width="match_parent"
        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" />
© www.soinside.com 2019 - 2024. All rights reserved.