Element at the bottom using AppBarLayout draws element behind Navigation bar











up vote
1
down vote

favorite












I am trying to have a navigation with fragments along different screens.
We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



So I use a NestedScrollView that will contain the fragments.
Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



The test is very easy to reproduce in the preview of the layout on AndroidStudio.



Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
Note that fitsSystemWindow does not make a difference for this.



This is just without using app:layout_scrollFlags="scroll"



enter image description here



This is using app:layout_scrollFlags="scroll"



enter image description here



This is the code for the simplified layout:



<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

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

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

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

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

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

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


also just in case this is the "content_main.xml"



    <?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:backgroundTint="@android:color/red"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>









share|improve this question




























    up vote
    1
    down vote

    favorite












    I am trying to have a navigation with fragments along different screens.
    We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



    So I use a NestedScrollView that will contain the fragments.
    Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



    So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



    The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



    The test is very easy to reproduce in the preview of the layout on AndroidStudio.



    Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
    Note that fitsSystemWindow does not make a difference for this.



    This is just without using app:layout_scrollFlags="scroll"



    enter image description here



    This is using app:layout_scrollFlags="scroll"



    enter image description here



    This is the code for the simplified layout:



    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

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

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

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

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

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

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


    also just in case this is the "content_main.xml"



        <?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    <Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:backgroundTint="@android:color/red"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
    </android.support.constraint.ConstraintLayout>









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying to have a navigation with fragments along different screens.
      We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



      So I use a NestedScrollView that will contain the fragments.
      Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



      So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



      The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



      The test is very easy to reproduce in the preview of the layout on AndroidStudio.



      Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
      Note that fitsSystemWindow does not make a difference for this.



      This is just without using app:layout_scrollFlags="scroll"



      enter image description here



      This is using app:layout_scrollFlags="scroll"



      enter image description here



      This is the code for the simplified layout:



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context=".MainActivity">

      <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay">

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

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

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

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

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

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


      also just in case this is the "content_main.xml"



          <?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:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"
      tools:showIn="@layout/activity_main">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World!"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      <Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="20dp"
      android:backgroundTint="@android:color/red"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent" />
      </android.support.constraint.ConstraintLayout>









      share|improve this question















      I am trying to have a navigation with fragments along different screens.
      We have decided that the Toolbar has to go away when scrolling. That is easy using AppBarLayout and layout_scrollFlags "scroll".



      So I use a NestedScrollView that will contain the fragments.
      Some fragments just contain a button that I want it to be placed at the bottom. Others are large menus that need to be scrollable.



      So for this purpose I use the flag fillViewPort on the NestedScrollView. In case the fragment is short, it will fill the screen and the button will appear at the bottom.



      The problem is that if I use the flag "scroll" on the AppBarLayout, if the fragment has a button on the bottom it is placed behind the navigation bar, while if I don't use the flag "scroll" NestedScrollView resizes to its proper size and the button is visible.



      The test is very easy to reproduce in the preview of the layout on AndroidStudio.



      Am I trying to do something weird? How can I achieve to have a button on the bottom for certain (small) fragments using the Coordinator and AppBarLayout with flags "scroll"?
      Note that fitsSystemWindow does not make a difference for this.



      This is just without using app:layout_scrollFlags="scroll"



      enter image description here



      This is using app:layout_scrollFlags="scroll"



      enter image description here



      This is the code for the simplified layout:



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      tools:context=".MainActivity">

      <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay">

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

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

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

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

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

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


      also just in case this is the "content_main.xml"



          <?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:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"
      tools:showIn="@layout/activity_main">

      <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Hello World!"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent" />

      <Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="20dp"
      android:backgroundTint="@android:color/red"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintStart_toStartOf="parent" />
      </android.support.constraint.ConstraintLayout>






      android android-layout android-fragments android-coordinatorlayout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 5:31









      Ümañg ßürmån

      2,9483829




      2,9483829










      asked Nov 22 at 5:25









      egonzal

      745




      745
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">

          <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay">

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

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

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

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer





















          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
            – egonzal
            Nov 22 at 17:13













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424381%2felement-at-the-bottom-using-appbarlayout-draws-element-behind-navigation-bar%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">

          <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay">

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

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

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

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer





















          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
            – egonzal
            Nov 22 at 17:13

















          up vote
          1
          down vote













          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">

          <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay">

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

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

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

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer





















          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
            – egonzal
            Nov 22 at 17:13















          up vote
          1
          down vote










          up vote
          1
          down vote









          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">

          <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay">

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

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

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

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.






          share|improve this answer












          Solution: Adding a <NestedScrollView> alone by itself below the AppBarLayout will avoid the visibility of the screen as it takes the Width and Height of the screen, but CoordinatorLayout will shift the view one below the other by default.



          Hence, the work-around would be to wrap the <NestedScrollView> in a separate layout like <LinearLayout> as shown below:



          <?xml version="1.0" encoding="utf-8"?>
          <android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">

          <android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay">

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

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

          <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

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

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

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

          </LinearLayout>

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


          And this will work as expected, you will be able to see the view and also hide the toolbar on scroll.



          Rest of the code remains the same. Try it, comment if any issues.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 6:44









          Ümañg ßürmån

          2,9483829




          2,9483829












          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
            – egonzal
            Nov 22 at 17:13




















          • Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
            – egonzal
            Nov 22 at 17:13


















          Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
          – egonzal
          Nov 22 at 17:13






          Yes! that made the trick. The only problem I see is that even with the button on the bottom the screen is still scrollable and toolbar goes away while scrolling, when actually there is nothing to scroll. But in any case, that is much better and much more usable. Thanks!
          – egonzal
          Nov 22 at 17:13




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424381%2felement-at-the-bottom-using-appbarlayout-draws-element-behind-navigation-bar%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu