android - How to make the FAB avoid being moved in ViewPager, yet be a part of the fragment within? -


background

according material design guidelines (here), if use viewpager has fab (floating action button) fragments within, fab shouldn't move part of fragments, either disappear or replaced another, or animate else.

in short, instead of this:

https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0b6okdz75tqqsnvrkv3fzmktvmwc/components-buttons-fab-behavior_06_xhdpi_009.webm

you should this:

https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0b6okdz75tqqsvlhxngjcnteznfu/components-buttons-fab-behavior_04_xhdpi_009.webm

the problem

i don't see example or tutorial of what's best way perform this.

i mean, having fab each fragment (or of them) in viewpager, while each controlled fragment (logic , how looks), yet fab won't move part of fragment while sliding between fragments in viewpager.

even example apps, don't see behavior anywhere. contacts app has same fab both fragments, , dialer has fab moving.

there apps use bad behavior (like solid-explorer). on youtube, there fab (on "account" fragment), it's on header, might ok there.

the question

how should implement correct behavior? put fab part of activity instead of fragments?

is there maybe tutorial and/or sample ?

maybe, when viewpager starts scrolling, detach fab, , attach activity, animate while being scrolled, , when it's done scrolling, hide , show 1 of other fragment?

i faced same problem viewpager , fab little time ago , solved in way:

  • attach fab activity above viewpager
  • add onpagechangelistener viewpager , save onpageselected(int position)'s position in global variable in activity
  • in onpageselected start anim of fab (it can both xml or programmatically, did xml) , change colortint
  • in onclicklistener's onclick(view v) when retrieve fab id (or view) of fab determine action should perform, can create switch statement position before in onpageselected

edit

these 2 anim.xml tried create similar android guidelines:

anim make disappear old fab:

<?xml version="1.0" encoding="utf-8"?> <set android:shareinterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android"> <scale     android:interpolator="@android:anim/accelerate_decelerate_interpolator"     android:fromxscale="1.0"     android:toxscale="0.0"     android:fromyscale="1.0"     android:toyscale="0.0"     android:pivotx="50%"     android:pivoty="50%"     android:fillafter="false"     android:duration="200" />  <rotate     android:duration="200"     android:interpolator="@android:anim/linear_interpolator"     android:pivotx="50%"     android:pivoty="50%"     android:fromdegrees="360"     android:todegrees="270" /> </set> 

anim show new one:

<?xml version="1.0" encoding="utf-8"?> <set android:shareinterpolator="false"     xmlns:android="http://schemas.android.com/apk/res/android">     <scale         android:interpolator="@android:anim/accelerate_decelerate_interpolator"         android:fromxscale="0.0"         android:toxscale="1.0"         android:fromyscale="0.0"         android:toyscale="1.0"         android:pivotx="50%"         android:pivoty="50%"         android:fillafter="false"         android:duration="200" />      <rotate         android:duration="200"         android:interpolator="@android:anim/linear_interpolator"         android:pivotx="50%"         android:pivoty="50%"         android:fromdegrees="270"         android:todegrees="360" /> </set> 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -