android - FAB animation with viewpager/tabslider -


i'm trying find way achieve such effect https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0b6okdz75tqqsvlhxngjcnteznfu/components-buttons-fab-behavior_04_xhdpi_009.webm

i'm using android.support.v4.view.viewpager

i appreciate hints ,

first, need have layout floating action button anchored viewpager:

<android.support.design.widget.coordinatorlayout     android:id="@+id/main_content"     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:theme="@style/themeoverlay.appcompat.dark.actionbar">          <android.support.v7.widget.toolbar             android:id="@+id/action_bar"             android:layout_width="match_parent"             android:layout_height="?attr/actionbarsize"             android:background="?attr/colorprimary"             app:layout_scrollflags="scroll|enteralways"             app:popuptheme="@style/themeoverlay.appcompat.light"/>          <android.support.design.widget.tablayout             android:id="@+id/tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="@android:color/white"             app:tabgravity="center"             app:tabindicatorcolor="?attr/coloraccent"             app:tabmode="scrollable"             app:tabselectedtextcolor="?attr/coloraccent"             app:tabtextcolor="@android:color/black" />      </android.support.design.widget.appbarlayout>      <android.support.v4.view.viewpager         android:id="@+id/viewpager"         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior" />       <android.support.design.widget.floatingactionbutton             android:id="@+id/fab"             app:layout_anchor="@id/viewpager"             app:layout_anchorgravity="bottom|right|end"             android:layout_width="56dp"             android:layout_height="56dp"             android:src="@drawable/ic_add_white"             app:borderwidth="@dimen/fab_border_width"             app:fabsize="normal" />  </android.support.design.widget.coordinatorlayout> 

now have fab anchored viewpager (note: i've tried on fragment tab in viewpager; not seem behave properly), add onpagechangelistener viewpager so:

 viewpager.addonpagechangelistener(new viewpager.onpagechangelistener() {         @override         public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) {         }          @override         public void onpageselected(int position) {              switch (position) {                 case index_of_tab_with_fab:                     fab.show();                     break;                  default:                     fab.hide();                     break;             }         }          @override         public void onpagescrollstatechanged(int state) {          }     }); 

the animations "pop" , "shrink" upon switching tabs handled automatically new version of support library.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -