android - CollapsingToolbarLayout inside Viewpager: toolbar acting strange -


i have viewpager fragments, each fragment should include collapsing toolbar + image header.

the layout fine have strange behaviour of toolbar, ignores top margin , ends under system bar. happens:

  • on first tab
  • after scrolling tab 3 or more, "first previus tab"
  • it happens on 1 tab @ time (as far can see)

also on first tab menu not inflated, despite oncreateoptionsmenu being run , not throwing error.

i reviewed code several times , made lots of adjustments but, sake of me, cannot find doing wrong!

adding screenshots , code. here a github repository if want run , see in action. help!

enter image description here enter image description here

and happens when scrolling left: enter image description here

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.view.viewpager     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/container"     android:layout_width="match_parent"     android:layout_height="match_parent"/> 

fragment_main.xml

<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:id="@+id/main_content"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fitssystemwindows="true"     tools:context="com.manzo.tabbednavigation.mainactivity">      <android.support.design.widget.appbarlayout         android:id="@+id/app_bar_layout"         android:layout_width="match_parent"         android:layout_height="@dimen/appbar_height"         android:fitssystemwindows="true"         android:theme="@style/apptheme.appbaroverlay">          <android.support.design.widget.collapsingtoolbarlayout             android:id="@+id/collapsing_toolbar_layout"             android:layout_width="match_parent"             android:layout_height="match_parent"             app:title="title"             app:contentscrim="?attr/colorprimary"             android:fitssystemwindows="true"             app:layout_scrollflags="scroll|exituntilcollapsed">               <imageview                 android:id="@+id/iv_scroll_header"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:scaletype="centercrop"                 app:layout_collapsemode="parallax"                 android:fitssystemwindows="true"                 android:src="@drawable/bg"/>              <android.support.v7.widget.toolbar                 android:id="@+id/toolbar"                 android:layout_width="match_parent"                 android:layout_height="?attr/actionbarsize"                 android:background="@color/coloraccentwarning"                 app:layout_collapsemode="pin"                 app:popuptheme="@style/apptheme.popupoverlay" />          </android.support.design.widget.collapsingtoolbarlayout>     </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">          <textview             android:id="@+id/section_label"             android:layout_width="wrap_content"             android:layout_height="wrap_content" />      </android.support.v4.widget.nestedscrollview> </android.support.design.widget.coordinatorlayout> 

i didn't found solution ended using workaround.

i removed fitssystemwindows="true" toolbar , added margintop of 24dp, system bar height per material guidelines, included height of 25dp previous sdks.

<android.support.v7.widget.toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionbarsize"             android:layout_margintop="@dimen/status_bar_height"             app:layout_collapsemode="pin"             app:popuptheme="@style/apptheme.popupoverlay" /> 

i open suggestion "real" solution


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -