/** * Updates the FAB location (middle to right position) as the PageView scrolls. * * @param positionOffset A fraction used to calculate position of the FAB during page scroll. */ public void onPageScrolled(float positionOffset) { // As the page is scrolling, if we're on the first tab, update the FAB position so it // moves along with it. mFloatingActionButtonContainer.setTranslationX( (int) (positionOffset * getTranslationXForAlignment(ALIGN_END))); }
/** * Aligns the FAB to the described location plus specified additional offsets. * * @param align One of ALIGN_MIDDLE, ALIGN_QUARTER_RIGHT, or ALIGN_RIGHT. * @param offsetX Additional offsetX to translate by. * @param offsetY Additional offsetY to translate by. * @param animate Whether or not to animate the transition. */ public void align(int align, int offsetX, int offsetY, boolean animate) { if (mScreenWidth == 0) { return; } int translationX = getTranslationXForAlignment(align); // Skip animation if container is not shown; animation causes container to show again. if (animate && mFloatingActionButtonContainer.isShown()) { mFloatingActionButtonContainer.animate() .translationX(translationX + offsetX) .translationY(offsetY) .setInterpolator(mFabInterpolator) .setDuration(mAnimationDuration) .start(); } else { mFloatingActionButtonContainer.setTranslationX(translationX + offsetX); mFloatingActionButtonContainer.setTranslationY(offsetY); } }