1

I am trying to get my navigation bar to appear on top of the body when scrolling. Currently it goes below as images shows.

I have a navdrawer also which has stopped working since introducing the scrollview... I feel as though this could be because when I click the 'hamburger' icon it is actually behind the scroll view so doesn't work but not sure... just want to get this bit done then I will find out if that the reason I guess. Thank you.

Layout xml for that page is also below.

What happens:

enter image description here

XML:

<?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"
android:id="@+id/RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:theme="@style/AppTheme">



  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/NwApt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="55dp"
        android:background="@color/colorS"
        android:padding="5dp"
        android:text="New Appointment"
        android:textColor="@color/PTextColour"
        android:textSize="18sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/activity_horizontal_margin"

        android:orientation="vertical">


        <EditText
            android:id="@+id/NEngNme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_marginTop="75dp"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Engineer Name"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/NItm"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Item"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/NDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Date"
            android:inputType="date" />


        <EditText
            android:id="@+id/NTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Time"
            android:inputType="time" />


        <EditText
            android:id="@+id/NLoc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Location"
            android:inputType="textPersonName" />


        <EditText
            android:id="@+id/NTstNotes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_weight="1"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Tester Notes"
            android:inputType="textMultiLine" />

        <EditText
            android:id="@+id/NScdNotes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_weight="1"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Scheduler Notes"
            android:inputType="textMultiLine" />


        <CheckBox
            android:id="@+id/NntsChkBx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_weight="1"
            android:text="Show Notes at appointment" />


        <CheckBox
            android:id="@+id/NaptChkBx"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:text="Missed Appointment" />


        <LinearLayout
            android:id="@+id/NButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2">

            <Button
                android:id="@+id/NSveNts"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Save Notes" />

            <Button
                android:id="@+id/NSndEml"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Send Email" />
        </LinearLayout>

        </LinearLayout>
       </RelativeLayout>

   </RelativeLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user3095083
  • 145
  • 9
  • Go through this link on [how to use coordinatior layout](http://saulmm.github.io/mastering-coordinator) and [this](https://stackoverflow.com/questions/32523188/coordinatorlayout-appbarlayout-navigationdrawer) for using coordinatior layout with drawerlayout. –  Dec 22 '17 at 12:36
  • That seems like a lot of rework, considering all the pages I have, is there any simpler way or will I have to take that approach? – user3095083 Dec 22 '17 at 12:39
  • No, actually it isn't. You just have to use the second [link](https://stackoverflow.com/questions/32523188/coordinatorlayout-appbarlayout-navigationdrawer) for this issue. See the accepted answer. –  Dec 22 '17 at 12:40
  • ~ see my answer. –  Dec 22 '17 at 12:54

1 Answers1

1

activity_edit_appointment.xml contains a DrawerLayout as a parent view with sub-subsequent children as CoordniatorLayout and NavigationView like this:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">

<android.support.design.widget.CoordinatorLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/overview_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimaryDark"
            app:layout_scrollFlags="enterAlways|scroll" />

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/your_contents" />

    </android.support.v4.widget.NestedScrollView>


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

<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/navigationdrawer_main" />
  </android.support.v4.widget.DrawerLayout>


your_contents.xml will contain views you want to display for current activity.

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:orientation="vertical">
        <EditText
            android:id="@+id/NEngNme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="75dp"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Engineer Name"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/NItm"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Item"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/NDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Date"
            android:inputType="date" />

        <EditText
            android:id="@+id/NTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Time"
            android:inputType="time" />

        <EditText
            android:id="@+id/NLoc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Location"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/NTstNotes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Tester Notes"
            android:inputType="textMultiLine" />

        <EditText
            android:id="@+id/NScdNotes"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:drawable/editbox_background_normal"
            android:ems="10"
            android:hint="Scheduler Notes"
            android:inputType="textMultiLine" />


        <CheckBox
            android:id="@+id/NntsChkBx"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Show Notes at appointment" />


        <CheckBox
            android:id="@+id/NaptChkBx"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Missed Appointment" />


        <LinearLayout
            android:id="@+id/NButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2">

            <Button
                android:id="@+id/NSveNts"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Save Notes" />

            <Button
                android:id="@+id/NSndEml"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Send Email" />
        </LinearLayout>

    </LinearLayout>

you can place your navigation drawer inside these 2 xml files: nav_header.xml(will give you a header like gmail app) and navigationdrawer_main.xml(specify your drawer entries inside this menu file)

To give title to the toolbar, you can either do it programatically or just give android:label="Edit Appointment" to this activity's activity tag in AndroidManifest.xml.

  • sorry I think I am slowing getting there!! Now using code above though I am getting DrawerLayout must be measured with MeasureSpec.EXACTLY error I can see it is something to do with the height/width just can't find the issue... any chance you know exactly what is causing it? – user3095083 Dec 22 '17 at 13:53