构建应具有的主应用布局:
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/