void onItemViewHeightChanged(int newHeight) { if ((prevHeight != 0) && (newHeight != prevHeight)) { final View view = getInnerLayout(); ViewCompat.setY(view, ViewCompat.getY(view) - (prevHeight - newHeight)); } prevHeight = newHeight; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void backgroundCircularRevealAnimation(View clickedView, final int newColor) { int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2)); int yOffset = isTabletMode ? (int) ViewCompat.getY(clickedView) : 0; int centerY = yOffset + clickedView.getMeasuredHeight() / 2; int startRadius = 0;
@Override public boolean onPreDraw() { //rotation fix, if not set, originalTitleY = Na ViewCompat.setTranslationY(mLogo,0); ViewCompat.setTranslationX(mLogo, 0); originalTitleY = ViewCompat.getY(mLogo); originalTitleX = ViewCompat.getX(mLogo); originalTitleHeight = mLogo.getHeight(); finalTitleHeight = dpToPx(21, context); //the final scale of the logo finalScale = finalTitleHeight / originalTitleHeight; finalTitleY = (toolbar.getPaddingTop() + toolbar.getHeight()) / 2 - finalTitleHeight / 2 - (1 - finalScale) * finalTitleHeight; //(mLogo.getWidth()/2) *(1-finalScale) is the margin left added by the scale() on the logo //when logo scaledown, the content stay in center, so we have to anually remove the left padding finalTitleX = dpToPx(52f, context) - (mLogo.getWidth() / 2) * (1 - finalScale); toolbarLayout.getViewTreeObserver().removeOnPreDrawListener(this); return false; } });
/** * move the toolbarlayout (containing toolbar & tabs) * following the current scroll */ private void followScrollToolbarLayout(float yOffset) { if (mHeader.toolbar.getBottom() == 0) { return; } if (toolbarJoinsTabs()) { if (firstScrollValue == Float.MIN_VALUE) { firstScrollValue = yOffset; } float translationY = firstScrollValue - yOffset; if (translationY > 0) { translationY = 0; } log("translationY " + translationY); ViewCompat.setTranslationY(mHeader.toolbarLayout, translationY); } else { ViewCompat.setTranslationY(mHeader.toolbarLayout, 0); justToolbarAnimated = false; } followScrollToolbarIsVisible = (ViewCompat.getY(mHeader.toolbarLayout) >= 0); }
if (ViewCompat.getY(mHeader.headerBackground) >= 0) { ViewCompat.setY(mHeader.headerBackground, 0); float newDistance = ViewCompat.getY(mHeader.mPagerSlidingTabStrip) - mHeader.toolbar.getBottom(); if (ViewCompat.getY(mHeader.mPagerSlidingTabStrip) < mHeader.getToolbar().getBottom()) { float ty = mHeader.getToolbar().getBottom() - mHeader.mPagerSlidingTabStrip.getTop(); ViewCompat.setTranslationY(mHeader.mPagerSlidingTabStrip, ty);
float getY(View view) { Rect rect = new Rect(); view.getGlobalVisibleRect(rect); float y = rect.top; if (y <= 0) { y = ViewCompat.getY(view); } return y; }
public static float getY(final @NonNull View v) { if (Build.VERSION.SDK_INT >= 11) { return ViewCompat.getY(v); } else { return ((ViewGroup.MarginLayoutParams) v.getLayoutParams()).topMargin; } }
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { if (mDivider == null) { return; } final int childCount = parent.getChildCount(); final int width = parent.getWidth(); final int dividerHeight = mDividerHeight != 0 ? mDividerHeight : mDividerIntrinsicHeight; for (int childViewIndex = 0; childViewIndex < childCount; childViewIndex++) { final View view = parent.getChildAt(childViewIndex); if (shouldDrawDividerBelow(view, parent)) { final int top = (int) ViewCompat.getY(view) + view.getHeight(); mDivider.setBounds(0, top, width, top + dividerHeight); mDivider.draw(c); } } }
private void animateViewIn(final View view, int position) { final float offsetY = getResources().getDimensionPixelSize(R.dimen.keyline_1); ViewCompat.setScaleX(view, 0.25f); ViewCompat.setScaleY(view, 0.25f); ViewCompat.setY(view, ViewCompat.getY(view) + offsetY); ViewCompat.animate(view) .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)) .scaleX(1f) .scaleY(1f) .translationYBy(-offsetY) .alpha(1f) .setStartDelay(4 * position * VSYNC_RHYTHM) .setInterpolator(new FastOutSlowInInterpolator()) .setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationStart(View view) { super.onAnimationStart(view); isAnimating = true; } @Override public void onAnimationEnd(View view) { super.onAnimationEnd(view); isAnimating = false; } }) .start(); }
private void animateViewIn(final View view, int position) { final float offsetY = getResources().getDimensionPixelSize(R.dimen.keyline_1); ViewCompat.setScaleX(view, 0.25f); ViewCompat.setScaleY(view, 0.25f); ViewCompat.setY(view, ViewCompat.getY(view) + offsetY); ViewCompat.animate(view) .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)) .scaleX(1f) .scaleY(1f) .translationYBy(-offsetY) .alpha(1f) .setStartDelay(4 * position * VSYNC_RHYTHM) .setInterpolator(new FastOutSlowInInterpolator()) .setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationStart(View view) { super.onAnimationStart(view); isAnimating = true; } @Override public void onAnimationEnd(View view) { super.onAnimationEnd(view); isAnimating = false; } }) .start(); }
private void animateViewIn(final View view, int position) { final float offsetY = getResources().getDimensionPixelSize(R.dimen.keyline_1); ViewCompat.setScaleX(view, 0.25f); ViewCompat.setScaleY(view, 0.25f); ViewCompat.setY(view, ViewCompat.getY(view) + offsetY); ViewCompat.animate(view) .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)) .scaleX(1f) .scaleY(1f) .translationYBy(-offsetY) .alpha(1f) .setStartDelay(4 * VSYNC_RHYTHM) .setInterpolator(new FastOutSlowInInterpolator()) .setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationStart(View view) { super.onAnimationStart(view); isAnimating = true; } @Override public void onAnimationEnd(View view) { super.onAnimationEnd(view); isAnimating = false; } }) .start(); }