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:
you should this:
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
, saveonpageselected(int position)
's position in global variable in activity - in
onpageselected
start anim of fab (it can both xml or programmatically, did xml) , changecolortint
- in
onclicklistener
'sonclick(view v)
when retrieve fab id (or view) of fab determine action should perform, can create switch statement position before inonpageselected
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
Post a Comment