android - 无法将 FrameLayout 放置在 ConstraintLayout 内

标签 android xml android-constraintlayout

构建应具有的主应用布局:

1) ConstraintLayout 作为 root - 因为它是relativelayout 的新趋势改变者

2) AppBarLayout 内有工具栏

3)底部的BottomNavigationView

4) FAB 位于 BNV 上方右下角

5) 和 FrameLayout - 我的 fragment 的容器,必须位于 AppBarLayout 和 BottomNavigationView 之间。

我无法定位我的 FrameLayout。它仅显示具有完整设备大小或 0dp 的 match_parent。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_constraintTop_toTopOf="@+id/frame_container">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@string/app_name">

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_constraintTop_toTopOf="parent">

    </FrameLayout>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:clickable="true"
        android:focusable="true"
        app:layout_constraintBottom_toTopOf="@+id/navigation"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@drawable/ic_home_black_24dp" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/primary"
        app:elevation="8dp"
        app:itemIconTint="@color/icons"
        app:itemTextColor="@color/icons"
        app:layout_constraintBottom_toBottomOf="@+id/frame_container"
        app:layout_insetEdge="bottom"
        app:menu="@menu/navigation" />

</android.support.constraint.ConstraintLayout>

最佳答案

像这样设置constraintTop和constraintBottom:

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:layout_constraintTop_toBottomOf="@+id/appbar"
    app:layout_constraintBottom_toTopOf="@+id/navigation">

还可以编辑其他 View 的约束

关于android - 无法将 FrameLayout 放置在 ConstraintLayout 内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48011434/

相关文章:

android - 约束布局不起作用,可能是设计编辑器中的错误?

java - 尝试绘制自定义 View 时崩溃 - InflateException

javascript - Python lxml 库无法解析 < 和 >

java - 通过 HTTP 将大型视频文件从 Tomcat 服务器传输到 Android 客户端

xml - 创建 'flexible' XML 架构

.net - MSTest 的 XML 单元测试框架

java - 如何在constraintlayout中实现可滚动和放大缩小

android - 无法解析类 android.support.constraint.ConstraintLayout

android - 如何在不更改主键的情况下执行 SQL Insert 或 Replace like operator?

javascript - 尝试从 webview 获取位置时出现 Android "SQLite database failed to load from/CachedGeoposition.db"错误