I need help with this xml layout because my Fragment
is under the toolbar.
I have tried all kinds of layouts attributes like layout_below
and more but no success. Also the NavigationView
is under the toolbar.
The ConstraintLayout
like app:layout_constraintTop_toTopOf
has no effect if I make the container ConstraintLayout
Here´s my xml hoping for some advice?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:autofit="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"
tools:context="com.port.android.ui.ActivityMain">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.port.android.ui.ActivityMain">
<android.support.constraint.ConstraintLayout
android:id="@+id/main_ConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
app:headerLayout="@layout/navigation_view_header"
app:menu="@menu/menu_navigation">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:padding="20dp">
<Button
android:id="@+id/btn_exit_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="exitAddress"
android:text="@string/exit_address" />
</LinearLayout>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
For those like me that will be, eventually, looking for an answer for that problem.
The way I fixed that was using a <ConstraintLayout>
and changing the child <FrameLayout>
layout_height
and layout_width
to "0dp"
which is equals to "MATCH_CONSTRAINT". Additionally, you should also add some constraint attributes like below.
Your <FrameLayout>
should look like this:
<FrameLayout
android:id="@+id/fragment_placeholder"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/main_toolbar"
app:layout_constraintBottom_toTopOf="@id/navigation"
/>
I hope it helps!
Try layout below in your drawer layout
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.port.android.ui.ActivityMain"
android:layout_below="@+id/appBarLayout_1">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With