Reputation: 229
Building main app layout that should have:
1) ConstraintLayout as root - because its new and trending changer of RelativeLayout
2) AppBarLayout with toolbar inside
3) BottomNavigationView at the bottom ofc
4) FAB at bottom right above BNV
5) And FrameLayout - container for my fragments that must be between AppBarLayout and BottomNavigationView.
I cant position my FrameLayout. It appears only match_parent with full device size or 0dp.
<?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>
Upvotes: 2
Views: 7997
Reputation: 8254
Set constraintTop and constraintBottom like this:
<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">
And also edit the constraints of the other Views
Upvotes: 5