Android-animate The Hiding/showing Of Toolbar On Swiping Between Tabs Like In Whatsapp Camera
i am successfull in showing and hiding of appbar when swiping between tabs in tablayout. but now i want to animate this hiding and appearing of tab smoothly like we do in switching
Solution 1:
The way to go about it is to translate the AppbarLayout
using its translationY attribute in onPageScrolled()
callback of the ViewPager
's OnPageChangeListener
interface using the AppbarLayout
's bottom value.
mViewPager.addOnPageChangeListener(newOnPageChangeListener(){
@OverridepublicvoidonPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
// get an instance of the appBarLayout This should probably be done at the activity level in its oncreate() method/* example:
public ViewPager mViewPager;
public AppBarLayout appBar;
onCreate(...){
...
mViewPager = (ViewPager) findViewById(R.id.viewpager);
appBar = (AppBarLayout) findViewById(R.id.appbar);
mViewPager.addOnPageChangeListener(...);
...
}
*/// set the position you want the app bar to be hidden on the ViewPagerinthideAppBarAtPosition=0;
if (appBar != null) {
// get an instance of the bottom value of the appBarfloatmBottom= (float) appBar.getBottom();
// going right offset changes from zero to oneif (position == hideAppBarAtPosition) {
// Translate the appBar up as the resideReveal slides into viewfloaty= (positionOffset * mBottom) - mBottom;
// Raise the appBar a little bit higher when it is no longer visibleif (y == -mBottom) {
floath= (float) appBar.getHeight();
if (mBottom < h) mBottom = h;
y = -mBottom - mBottom / 8f;
}
appBar.setTranslationY(y);
} elseif (position == hideAppBarAtPosition - 1) {
// Translate the appBar up as the resideReveal slides into view
appBar.setTranslationY(-(positionOffset * mBottom));
} elseif (appBar.getTranslationY() != 0f) {
// Reset translation of the appBar
appBar.setTranslationY(0f);
}
}
}
@OverridepublicvoidonPageSelected(int position) {
}
@OverridepublicvoidonPageScrollStateChanged(int state) {
}
});
If you need more ideas on how to implement it, view this open source project https://github.com/goody-h/ResidingTab
Post a Comment for "Android-animate The Hiding/showing Of Toolbar On Swiping Between Tabs Like In Whatsapp Camera"