Java Code Examples for com.nineoldandroids.view.ViewHelper#setScaleY()

The following examples show how to use com.nineoldandroids.view.ViewHelper#setScaleY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JazzyViewPager.java    From android-kernel-tweaker with GNU General Public License v3.0 7 votes vote down vote up
protected void animateStack(View left, View right, float positionOffset, int positionOffsetPixels) {		
	if (mState != State.IDLE) {
		if (right != null) {
			manageLayer(right, true);
			mScale = (1-SCALE_MAX) * positionOffset + SCALE_MAX;
			mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
			ViewHelper.setTranslationX(right, mTrans);
		}
		if (left != null) {
			left.bringToFront();
		}
	}
}
 
Example 2
Source File: FlexibleSpaceWithImageWithViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
private void updateFlexibleSpace(float translationY) {
    ViewHelper.setTranslationY(mInterceptionLayout, translationY);
    int minOverlayTransitionY = getActionBarSize() - mOverlayView.getHeight();
    ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-translationY / 2, minOverlayTransitionY, 0));

    // Change alpha of overlay
    float flexibleRange = mFlexibleSpaceHeight - getActionBarSize();
    ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat(-translationY / flexibleRange, 0, 1));

    // Scale title text
    float scale = 1 + ScrollUtils.getFloat((flexibleRange + translationY - mTabHeight) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA);
    setPivotXToTitle();
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);
}
 
Example 3
Source File: FlexibleSpaceToolbarWebViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
private void updateFlexibleSpaceText(final int scrollY) {
    ViewHelper.setTranslationY(mFlexibleSpaceView, -scrollY);
    int adjustedScrollY = (int) ScrollUtils.getFloat(scrollY, 0, mFlexibleSpaceHeight);

    // Special logic for WebView.
    adjustTopMargin(mWebViewContainer, adjustedScrollY <= mFlexibleSpaceHeight ? 0 : mFlexibleSpaceHeight + getActionBarSize());

    float maxScale = (float) (mFlexibleSpaceHeight - mToolbarView.getHeight()) / mToolbarView.getHeight();
    float scale = maxScale * ((float) mFlexibleSpaceHeight - adjustedScrollY) / mFlexibleSpaceHeight;

    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, 1 + scale);
    ViewHelper.setScaleY(mTitleView, 1 + scale);
    int maxTitleTranslationY = mToolbarView.getHeight() + mFlexibleSpaceHeight - (int) (mTitleView.getHeight() * (1 + scale));
    int titleTranslationY = (int) (maxTitleTranslationY * ((float) mFlexibleSpaceHeight - adjustedScrollY) / mFlexibleSpaceHeight);
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);
}
 
Example 4
Source File: JazzyViewPager.java    From Gazetti_Newspaper_Reader with MIT License 6 votes vote down vote up
private void animateZoom(View left, View right, float positionOffset, boolean in) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mScale = in ? ZOOM_MAX + (1-ZOOM_MAX)*(1-positionOffset) :
				1+ZOOM_MAX - ZOOM_MAX*(1-positionOffset);
			ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
			ViewHelper.setScaleX(left, mScale);
			ViewHelper.setScaleY(left, mScale);
		}
		if (right != null) {
			manageLayer(right, true);
			mScale = in ? ZOOM_MAX + (1-ZOOM_MAX)*positionOffset :
				1+ZOOM_MAX - ZOOM_MAX*positionOffset;
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
		}
	}
}
 
Example 5
Source File: ForegroundToBackgroundTransformer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float height = view.getHeight();
	final float width = view.getWidth();
	final float scale = min(position > 0 ? 1f : Math.abs(1f + position), 0.5f);

	ViewHelper.setScaleX(view,scale);
       ViewHelper.setScaleY(view,scale);
       ViewHelper.setPivotX(view,width * 0.5f);
       ViewHelper.setPivotY(view,height * 0.5f);
       ViewHelper.setTranslationX(view,position > 0 ? width * position : -width * position * 0.25f);
}
 
Example 6
Source File: JazzyViewPager.java    From ClockView with Apache License 2.0 5 votes vote down vote up
private void animateZoom(View left, View right, float positionOffset,
		boolean in)
{
	if (mState != State.IDLE)
	{
		if (left != null)
		{
			manageLayer(left, true);
			mScale = in ? ZOOM_MAX + (1 - ZOOM_MAX) * (1 - positionOffset)
					: 1 + ZOOM_MAX - ZOOM_MAX * (1 - positionOffset);
			ViewHelper.setPivotX(left, left.getMeasuredWidth());
			ViewHelper.setPivotY(left, left.getMeasuredHeight() * 0.5f);
			ViewHelper.setScaleX(left, mScale);
			ViewHelper.setScaleY(left, mScale);
		}
		if (right != null)
		{
			manageLayer(right, true);
			mScale = in ? ZOOM_MAX + (1 - ZOOM_MAX) * positionOffset : 1
					+ ZOOM_MAX - ZOOM_MAX * positionOffset;
			ViewHelper.setPivotX(right, 0);
			ViewHelper.setPivotY(right, right.getMeasuredHeight() * 0.5f);
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
		}
	}
}
 
Example 7
Source File: BackgroundToForegroundTransformer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float height = view.getHeight();
	final float width = view.getWidth();
	final float scale = min(position < 0 ? 1f : Math.abs(1f - position), 0.5f);

       ViewHelper.setScaleX(view,scale);
       ViewHelper.setScaleY(view,scale);
       ViewHelper.setPivotX(view,width*0.5f);
       ViewHelper.setPivotY(view,height*0.5f);
       ViewHelper.setTranslationX(view,position < 0 ? width * position : -width * position * 0.25f);
}
 
Example 8
Source File: BackgroundToForegroundTransformer.java    From ImageSliderWithSwipes with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float height = view.getHeight();
	final float width = view.getWidth();
	final float scale = min(position < 0 ? 1f : Math.abs(1f - position), 0.5f);

       ViewHelper.setScaleX(view,scale);
       ViewHelper.setScaleY(view,scale);
       ViewHelper.setPivotX(view,width*0.5f);
       ViewHelper.setPivotY(view,height*0.5f);
       ViewHelper.setTranslationX(view,position < 0 ? width * position : -width * position * 0.25f);
}
 
Example 9
Source File: JazzyViewPager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected void animateStack(View left, View right, float positionOffset, int positionOffsetPixels) {
    if (mState != State.IDLE) {
        if (right != null) {
            manageLayer(right, true);
            mScale = (1 - SCALE_MAX) * positionOffset + SCALE_MAX;
            mTrans = -getWidth() - getPageMargin() + positionOffsetPixels;
            ViewHelper.setScaleX(right, mScale);
            ViewHelper.setScaleY(right, mScale);
            ViewHelper.setTranslationX(right, mTrans);
        }
        if (left != null) {
            left.bringToFront();
        }
    }
}
 
Example 10
Source File: RecentsList.java    From MaterialRecents with Apache License 2.0 5 votes vote down vote up
private void layoutChildren() {
    int width = getWidth() - getPaddingLeft() - getPaddingRight();
    int height = getHeight() - getPaddingTop() - getPaddingBottom();
    for (int i = 0; i < getChildCount(); i++) {
        float topSpace = height - width;
        int y = (int) (topSpace * Math.pow(2, (i * width - scroll) / (float) width));
        float scale = (float) (-Math.pow(2, -y / topSpace / 10.0f) + 19.0f / 10);
        childTouchRect[i].set(getPaddingLeft(), y + getPaddingTop(), (int) (scale * (getPaddingLeft() + getWidth() - getPaddingLeft() - getPaddingRight())), (int) (scale * (y + getPaddingTop() + getWidth() - getPaddingLeft() - getPaddingRight())));
        ViewHelper.setTranslationX(getChildAt(i), getPaddingLeft());
        ViewHelper.setTranslationY(getChildAt(i), y + getPaddingTop());
        ViewHelper.setScaleX(getChildAt(i), scale);
        ViewHelper.setScaleY(getChildAt(i), scale);
    }
}
 
Example 11
Source File: JazzyViewPager.java    From Contacts with MIT License 5 votes vote down vote up
protected void animateStack(View left, View right, float positionOffset, int positionOffsetPixels) {		
	if (mState != State.IDLE) {
		if (right != null) {
			manageLayer(right, true);
			mScale = (1-SCALE_MAX) * positionOffset + SCALE_MAX;
			mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
			ViewHelper.setTranslationX(right, mTrans);
		}
		if (left != null) {
			left.bringToFront();
		}
	}
}
 
Example 12
Source File: MaterialCompoundButton.java    From MaterialRadioGroup with Apache License 2.0 5 votes vote down vote up
public MaterialCompoundButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    LayoutInflater.from(context).inflate(R.layout.mcl_compound_button, this, true);
    mButtonView = (MaterialStateButton) findViewById(R.id.mci_compound_button_image);
    mSpaceView = findViewById(R.id.mci_compound_button_padding);
    mButtonText = (MaterialStateText) findViewById(R.id.mci_compound_button_text);
    mButtonView.setOnStateButtonCheckedListener(this);
    applyAttributeSet(context, attrs);
    if(isAnimator()){
        ViewHelper.setScaleX(this, 0.85f);
        ViewHelper.setScaleY(this, 0.85f);
    }
}
 
Example 13
Source File: RotateTransformer.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void transformPage(View view, float position) {
	if (position < -1) {
	} else if (position <= 0) {
		ViewHelper.setScaleX(view, 1 + position);
		ViewHelper.setScaleY(view, 1 + position);
		ViewHelper.setRotation(view, 360 * position);
	} else if (position <= 1) {
		ViewHelper.setScaleX(view, 1 - position);
		ViewHelper.setScaleY(view, 1 - position);
		ViewHelper.setRotation(view, 360 * position);
	} else {
	}
}
 
Example 14
Source File: ImagePagerFragment.java    From PhotoPicker with Apache License 2.0 5 votes vote down vote up
/**
 * The enter animation scales the picture in from its previous thumbnail
 * size/location, colorizing it in parallel. In parallel, the background of the
 * activity is fading in. When the pictue is in place, the text description
 * drops down.
 */
private void runEnterAnimation() {
  final long duration = ANIM_DURATION;

  // Set starting values for properties we're going to animate. These
  // values scale and position the full size version down to the thumbnail
  // size/location, from which we'll animate it back up
  ViewHelper.setPivotX(mViewPager, 0);
  ViewHelper.setPivotY(mViewPager, 0);
  ViewHelper.setScaleX(mViewPager, (float) thumbnailWidth / mViewPager.getWidth());
  ViewHelper.setScaleY(mViewPager, (float) thumbnailHeight / mViewPager.getHeight());
  ViewHelper.setTranslationX(mViewPager, thumbnailLeft);
  ViewHelper.setTranslationY(mViewPager, thumbnailTop);

  // Animate scale and translation to go from thumbnail to full size
  ViewPropertyAnimator.animate(mViewPager)
      .setDuration(duration)
      .scaleX(1)
      .scaleY(1)
      .translationX(0)
      .translationY(0)
      .setInterpolator(new DecelerateInterpolator());

  // Fade in the black background
  ObjectAnimator bgAnim = ObjectAnimator.ofInt(mViewPager.getBackground(), "alpha", 0, 255);
  bgAnim.setDuration(duration);
  bgAnim.start();

  // Animate a color filter to take the image from grayscale to full color.
  // This happens in parallel with the image scaling and moving into place.
  ObjectAnimator colorizer = ObjectAnimator.ofFloat(ImagePagerFragment.this,
      "saturation", 0, 1);
  colorizer.setDuration(duration);
  colorizer.start();

}
 
Example 15
Source File: Util.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
public static void reset(View target) {
    ViewHelper.setAlpha(target, 1);
    ViewHelper.setScaleX(target, 1);
    ViewHelper.setScaleY(target, 1);
    ViewHelper.setTranslationX(target, 0);
    ViewHelper.setTranslationY(target, 0);
    ViewHelper.setRotation(target, 0);
    ViewHelper.setRotationY(target, 0);
    ViewHelper.setRotationX(target, 0);
    ViewHelper.setPivotX(target, target.getMeasuredWidth() / 2.0f);
    ViewHelper.setPivotY(target, target.getMeasuredHeight() / 2.0f);
}
 
Example 16
Source File: JazzyViewPager.java    From Gazetti_Newspaper_Reader with MIT License 5 votes vote down vote up
protected void animateStack(View left, View right, float positionOffset, int positionOffsetPixels) {		
	if (mState != State.IDLE) {
		if (right != null) {
			manageLayer(right, true);
			mScale = (1-SCALE_MAX) * positionOffset + SCALE_MAX;
			mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
			ViewHelper.setScaleX(right, mScale);
			ViewHelper.setScaleY(right, mScale);
			ViewHelper.setTranslationX(right, mTrans);
		}
		if (left != null) {
			left.bringToFront();
		}
	}
}
 
Example 17
Source File: FlexibleSpaceWithImageListViewActivity.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Translate overlay and image
    float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
    int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
    ViewHelper.setTranslationY(mOverlayView, Math.max(minOverlayTransitionY, Math.min(0, -scrollY)));
    ViewHelper.setTranslationY(mImageView, Math.max(minOverlayTransitionY, Math.min(0, -scrollY / 2)));

    // Translate list background
    ViewHelper.setTranslationY(mListBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight));

    // Change alpha of overlay
    ViewHelper.setAlpha(mOverlayView, Math.max(0, Math.min(1, (float) scrollY / flexibleRange)));

    // Scale title text
    float scale = 1 + Math.max(0, Math.min(MAX_TEXT_SCALE_DELTA, (flexibleRange - scrollY) / flexibleRange));
    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);

    // Translate title text
    int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
    int titleTranslationY = maxTitleTranslationY - scrollY;
    if (TOOLBAR_IS_STICKY) {
        titleTranslationY = Math.max(0, titleTranslationY);
    }
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);

    // Translate FAB
    int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
    int fabTranslationY = Math.max(mActionBarSize - mFab.getHeight() / 2,
            Math.min(maxFabTranslationY, -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2));
    ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
    ViewHelper.setTranslationY(mFab, fabTranslationY);

    // Show/hide FAB
    if (ViewHelper.getTranslationY(mFab) < mFlexibleSpaceShowFabOffset) {
        hideFab();
    } else {
        showFab();
    }

    if (TOOLBAR_IS_STICKY) {
        // Change alpha of toolbar background
        if (-scrollY + mFlexibleSpaceImageHeight <= mActionBarSize) {
            setBackgroundAlpha(mToolbar, 1, mToolbarColor);
        } else {
            setBackgroundAlpha(mToolbar, 0, mToolbarColor);
        }
    } else {
        // Translate Toolbar
        if (scrollY < mFlexibleSpaceImageHeight) {
            ViewHelper.setTranslationY(mToolbar, 0);
        } else {
            ViewHelper.setTranslationY(mToolbar, -scrollY);
        }
    }
}
 
Example 18
Source File: BaseTransformer.java    From ImageSliderWithSwipes with Apache License 2.0 4 votes vote down vote up
/**
 * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called.
 *
 * @param view
 * @param position
 */
protected void onPreTransform(View view, float position) {
    final float width = view.getWidth();

    ViewHelper.setRotationX(view,0);
    ViewHelper.setRotationY(view,0);
    ViewHelper.setRotation(view,0);
    ViewHelper.setScaleX(view,1);
    ViewHelper.setScaleY(view,1);
    ViewHelper.setPivotX(view,0);
    ViewHelper.setPivotY(view,0);
    ViewHelper.setTranslationY(view,0);
    ViewHelper.setTranslationX(view,isPagingEnabled() ? 0f : -width * position);

    if (hideOffscreenPages()) {
        ViewHelper.setAlpha(view,position <= -1f || position >= 1f ? 0f : 1f);
    } else {
        ViewHelper.setAlpha(view,1f);
    }
    if(mCustomAnimationInterface != null){
        if(h.containsKey(view) == false || h.get(view).size() == 1){
            if(position > -1 && position < 1){
                if(h.get(view) == null){
                    h.put(view,new ArrayList<Float>());
                }
                h.get(view).add(position);
                if(h.get(view).size() == 2){
                    float zero = h.get(view).get(0);
                    float cha = h.get(view).get(1) - h.get(view).get(0);
                    if(zero > 0){
                        if(cha > -1 && cha < 0){
                            //in
                            mCustomAnimationInterface.onPrepareNextItemShowInScreen(view);
                        }else{
                            //out
                            mCustomAnimationInterface.onPrepareCurrentItemLeaveScreen(view);
                        }
                    }else{
                        if(cha > -1 && cha < 0){
                            //out
                            mCustomAnimationInterface.onPrepareCurrentItemLeaveScreen(view);
                        }else{
                            //in
                            mCustomAnimationInterface.onPrepareNextItemShowInScreen(view);
                        }
                    }
                }
            }
        }
    }
}
 
Example 19
Source File: ResideMenu.java    From GifAssistant with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
    if (currentActivityScaleX == 1.0f)
        setScaleDirectionByRawX(ev.getRawX());

    switch (ev.getAction()){
        case MotionEvent.ACTION_DOWN:
            lastActionDownX = ev.getX();
            lastActionDownY = ev.getY();
            isInIgnoredView = isInIgnoredView(ev) && !isOpened();
            pressedState    = PRESSED_DOWN;
            break;

        case MotionEvent.ACTION_MOVE:
            if (isInIgnoredView || isInDisableDirection(scaleDirection))
                break;

            if(pressedState != PRESSED_DOWN &&
                    pressedState != PRESSED_MOVE_HORIZANTAL)
                break;

            int xOffset = (int) (ev.getX() - lastActionDownX);
            int yOffset = (int) (ev.getY() - lastActionDownY);

            if(pressedState == PRESSED_DOWN) {
                if(yOffset > 25 || yOffset < -25) {
                    pressedState = PRESSED_MOVE_VERTICAL;
                    break;
                }
                if(xOffset < -50 || xOffset > 50) {
                    pressedState = PRESSED_MOVE_HORIZANTAL;
                    ev.setAction(MotionEvent.ACTION_CANCEL);
                    lastRawX = ev.getRawX();
                    return true;
                }
            } else if(pressedState == PRESSED_MOVE_HORIZANTAL) {
                if (currentActivityScaleX < 0.95)
                    scrollViewMenu.setVisibility(VISIBLE);

                float targetScale = getTargetScale(ev.getRawX());
                ViewHelper.setScaleX(viewActivity, targetScale);
                ViewHelper.setScaleY(viewActivity, targetScale);
                ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX);
                ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY);
                ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

                lastRawX = ev.getRawX();
                return true;
            }

            break;

        case MotionEvent.ACTION_UP:

            if (isInIgnoredView) break;
            if (pressedState != PRESSED_MOVE_HORIZANTAL) break;

            pressedState = PRESSED_DONE;
            if (isOpened()){
                if (currentActivityScaleX > 0.56f) {
                    closeMenu();
                } else {
                    openMenu(scaleDirection);
                }
            }else{
                if (currentActivityScaleX < 0.94f){
                    openMenu(scaleDirection);
                }else{
                    closeMenu();
                }
            }
            lastRawX = ev.getRawX();
            return true;

            //break;

    }
    lastRawX = ev.getRawX();
    return super.dispatchTouchEvent(ev);
}
 
Example 20
Source File: FlexibleSpaceWithImageScrollViewActivity.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
    // Translate overlay and image
    float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize;
    int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight();
    ViewHelper.setTranslationY(mOverlayView, Math.max(minOverlayTransitionY, Math.min(0, -scrollY)));
    ViewHelper.setTranslationY(mImageView, Math.max(minOverlayTransitionY, Math.min(0, -scrollY / 2)));

    // Change alpha of overlay
    ViewHelper.setAlpha(mOverlayView, Math.max(0, Math.min(1, (float) scrollY / flexibleRange)));

    // Scale title text
    float scale = 1 + Math.max(0, Math.min(MAX_TEXT_SCALE_DELTA, (flexibleRange - scrollY) / flexibleRange));
    ViewHelper.setPivotX(mTitleView, 0);
    ViewHelper.setPivotY(mTitleView, 0);
    ViewHelper.setScaleX(mTitleView, scale);
    ViewHelper.setScaleY(mTitleView, scale);

    // Translate title text
    int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale);
    int titleTranslationY = maxTitleTranslationY - scrollY;
    if (TOOLBAR_IS_STICKY) {
        titleTranslationY = Math.max(0, titleTranslationY);
    }
    ViewHelper.setTranslationY(mTitleView, titleTranslationY);

    // Translate FAB
    int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2;
    int fabTranslationY = Math.max(mActionBarSize - mFab.getHeight() / 2,
            Math.min(maxFabTranslationY, -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2));
    ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth());
    ViewHelper.setTranslationY(mFab, fabTranslationY);

    // Show/hide FAB
    if (ViewHelper.getTranslationY(mFab) < mFlexibleSpaceShowFabOffset) {
        hideFab();
    } else {
        showFab();
    }

    if (TOOLBAR_IS_STICKY) {
        // Change alpha of toolbar background
        if (-scrollY + mFlexibleSpaceImageHeight <= mActionBarSize) {
            setBackgroundAlpha(mToolbar, 1, mToolbarColor);
        } else {
            setBackgroundAlpha(mToolbar, 0, mToolbarColor);
        }
    } else {
        // Translate Toolbar
        if (scrollY < mFlexibleSpaceImageHeight) {
            ViewHelper.setTranslationY(mToolbar, 0);
        } else {
            ViewHelper.setTranslationY(mToolbar, -scrollY);
        }
    }
}