Java Code Examples for android.support.v4.view.ViewCompat#setTranslationY()

The following examples show how to use android.support.v4.view.ViewCompat#setTranslationY() . 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: BaseItemAnimator.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    resetAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 2
Source File: BaseItemAnimator.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
Example 3
Source File: BaseItemAnimator.java    From onboarding-examples-android with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
Example 4
Source File: BaseItemAnimator.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    resetAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 5
Source File: BaseItemAnimator.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
Example 6
Source File: FloatLabelLayout.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Hide the label
 */
private void hideLabel(boolean animate) {
    if (animate) {
        float scale = mEditText.getTextSize() / mLabel.getTextSize();
        ViewCompat.setScaleX(mLabel, 1f);
        ViewCompat.setScaleY(mLabel, 1f);
        ViewCompat.setTranslationY(mLabel, 0f);

        ViewCompat.animate(mLabel)
                .translationY(mLabel.getHeight())
                .setDuration(ANIMATION_DURATION)
                .scaleX(scale)
                .scaleY(scale)
                .setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(View view) {
                        mLabel.setVisibility(INVISIBLE);
                        mEditText.setHint(mHint);
                    }
                })
                .setInterpolator(mInterpolator).start();
    } else {
        mLabel.setVisibility(INVISIBLE);
        mEditText.setHint(mHint);
    }
}
 
Example 7
Source File: MaterialViewPagerAnimator.java    From MaterialViewPager with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: OverlayViewBehavior.java    From material-scrolling with Apache License 2.0 5 votes vote down vote up
@Override
protected void onScrolled(View target, int scrollY, int dy) {
    final int movingHeight = getFlexibleHeight() - until;
    ViewCompat.setTranslationY(target, -Math.min(scrollY, movingHeight));
    if (scrollY >= movingHeight) {
        target.setBackgroundColor(Color.rgb(33, 33, 33));
    } else {
        final int alpha = 255 * scrollY / movingHeight;
        target.setBackgroundColor(Color.argb(alpha, 33, 33, 33));
    }
}
 
Example 9
Source File: CustomItemAnimator.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    if (holder instanceof AnimatorViewHolder) {
        if (!((AnimatorViewHolder) holder).performAnimation()) {
            return false;
        }
    }
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    resetAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 10
Source File: MainActivity.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
@Override
protected void preAnimateAdd(RecyclerView.ViewHolder holder) {
    if(!mSearchView.isActivated()) return;
    ViewCompat.setTranslationX(holder.itemView, 0);
    ViewCompat.setTranslationY(holder.itemView, -holder.itemView.getHeight());
    ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 11
Source File: FooterAbsListViewScrollListener.java    From AbsListViewHelper with MIT License 5 votes vote down vote up
public FooterAbsListViewScrollListener(View footerView, Bundle savedState) {
    this.footerView = footerView;

    if (savedState != null) {
        paddingBottom = savedState.getInt("FOOTER_PADDING");
        translationY = savedState.getFloat("FOOTER_TRANSLATION_Y");
        ViewCompat.setTranslationY(footerView, translationY);
    }
}
 
Example 12
Source File: DotStyleHorizontalRightRefreshViewHolder.java    From ht-refreshrecyclerview with MIT License 5 votes vote down vote up
@Override
public void onRefreshPositionChange(float scale, float moveXDistance, int refreshStatus, HTViewHolderTracker viewHolderTracker) {
    if (refreshStatus != HTBaseRecyclerView.RefreshStatus.REFRESH_PREPARE || viewHolderTracker.hasJustLeftIdlePosition()) {
        return;
    }
    float diffX = moveXDistance + mRefreshLoadView.getX() - mRefreshView.getMeasuredWidth();
    if (diffX > 0) {
        diffX = diffX >= maxXValue ? maxXValue : diffX;
        ViewCompat.setTranslationY(mRefreshLoadView.getChildAt(0), -diffX);
        ViewCompat.setTranslationY(mRefreshLoadView.getChildAt(1), diffX);
    } else {
        ViewCompat.setTranslationY(mRefreshLoadView.getChildAt(0), 0);
        ViewCompat.setTranslationY(mRefreshLoadView.getChildAt(1), 0);
    }
}
 
Example 13
Source File: BaseViewAnimator.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
/**
 * reset the view to default status
 *
 * @param target
 */
public void reset(View target) {
    ViewCompat.setAlpha(target, 1);
    ViewCompat.setScaleX(target, 1);
    ViewCompat.setScaleY(target, 1);
    ViewCompat.setTranslationX(target, 0);
    ViewCompat.setTranslationY(target, 0);
    ViewCompat.setRotation(target, 0);
    ViewCompat.setRotationY(target, 0);
    ViewCompat.setRotationX(target, 0);
}
 
Example 14
Source File: MaterialFooterView.java    From styT with Apache License 2.0 5 votes vote down vote up
@Override
public void onComlete(MaterialRefreshLayout materialRefreshLayout) {
    if (materialWaveView != null) {
        materialWaveView.onComlete(materialRefreshLayout);
    }
    if (circleProgressBar != null) {
        circleProgressBar.onComlete(materialRefreshLayout);
        ViewCompat.setTranslationY(circleProgressBar, 0);
        ViewCompat.setScaleX(circleProgressBar, 0);
        ViewCompat.setScaleY(circleProgressBar, 0);
    }


}
 
Example 15
Source File: ViewOffsetHelper.java    From SpringHeader with Apache License 2.0 4 votes vote down vote up
private static void tickleInvalidationFlag(View view) {
    final float x = ViewCompat.getTranslationX(view);
    ViewCompat.setTranslationY(view, x + 1);
    ViewCompat.setTranslationY(view, x);
}
 
Example 16
Source File: FromTopItemAnimator.java    From RecyclerViewLib with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean prepHolderForAnimateAdd(ViewHolder holder) {
    int bottom = holder.itemView.getBottom();
    ViewCompat.setTranslationY(holder.itemView, - bottom);
    return true;
}
 
Example 17
Source File: DefaultItemAnimator.java    From letv with Apache License 2.0 4 votes vote down vote up
public void endAnimation(ViewHolder item) {
    int i;
    View view = item.itemView;
    ViewCompat.animate(view).cancel();
    for (i = this.mPendingMoves.size() - 1; i >= 0; i--) {
        if (((MoveInfo) this.mPendingMoves.get(i)).holder == item) {
            ViewCompat.setTranslationY(view, 0.0f);
            ViewCompat.setTranslationX(view, 0.0f);
            dispatchMoveFinished(item);
            this.mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(this.mPendingChanges, item);
    if (this.mPendingRemovals.remove(item)) {
        ViewCompat.setAlpha(view, 1.0f);
        dispatchRemoveFinished(item);
    }
    if (this.mPendingAdditions.remove(item)) {
        ViewCompat.setAlpha(view, 1.0f);
        dispatchAddFinished(item);
    }
    for (i = this.mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = (ArrayList) this.mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            this.mChangesList.remove(i);
        }
    }
    for (i = this.mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = (ArrayList) this.mMovesList.get(i);
        int j = moves.size() - 1;
        while (j >= 0) {
            if (((MoveInfo) moves.get(j)).holder == item) {
                ViewCompat.setTranslationY(view, 0.0f);
                ViewCompat.setTranslationX(view, 0.0f);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    this.mMovesList.remove(i);
                }
            } else {
                j--;
            }
        }
    }
    for (i = this.mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = (ArrayList) this.mAdditionsList.get(i);
        if (additions.remove(item)) {
            ViewCompat.setAlpha(view, 1.0f);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                this.mAdditionsList.remove(i);
            }
        }
    }
    if (this.mRemoveAnimations.remove(item)) {
    }
    if (this.mAddAnimations.remove(item)) {
    }
    if (this.mChangeAnimations.remove(item)) {
    }
    if (this.mMoveAnimations.remove(item)) {
        dispatchFinishedWhenDone();
    } else {
        dispatchFinishedWhenDone();
    }
}
 
Example 18
Source File: ParallaxBehavior.java    From material-scrolling with Apache License 2.0 4 votes vote down vote up
@Override
protected void computeTranslation(final View target, final int scrollY, final int y) {
    ViewCompat.setTranslationY(target, -scrollY / parallaxRate);
}
 
Example 19
Source File: GarageDoorItemAnimator.java    From RecyclerViewLib with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean prepHolderForAnimateAdd(ViewHolder holder) {
    ViewCompat.setRotationX(holder.itemView, 90);
    ViewCompat.setTranslationY(holder.itemView, - (holder.itemView.getMeasuredHeight() / 2));
    return true;
}
 
Example 20
Source File: GearLoadingLayout.java    From GearLoadingProject with Apache License 2.0 4 votes vote down vote up
private void selectShowAnimation(boolean showDialog) {
    if (mActivityContentView == null || isAnimating)
        return;

    if (showDialog) {
        mActivityContentView.addView(GearLoadingLayout.this);
    }

    this.showDialog = showDialog;
    float from = 0f;
    float to = 0f;
    boolean xAxis = false;
    boolean scaleDialog = false;


    switch (mShowMode) {
        case TOP:
            from = -mDialogHeight;
            to = 0;
            break;
        case BOTTOM:
            from = mDialogHeight;
            to = 0;
            break;
        case LEFT:
            from = -mDialogWidth;
            to = 0;
            xAxis = true;
            break;
        case RIGHT:
            from = mDialogWidth;
            to = 0;
            xAxis = true;
            break;
        case CENTER:
            scaleDialog = true;
            break;
        default:
            break;
    }

    setGearLayoutWrapperGravity();
    applyStyle();
    start();
    if (scaleDialog) {
        ViewCompat.setScaleX(mGearLayoutWrapper, showDialog ? 0 : 1);
        ViewCompat.setScaleY(mGearLayoutWrapper, showDialog ? 0 : 1);
        ViewCompat.animate(mGearLayoutWrapper).scaleX(showDialog ? 1 : 0).scaleY(showDialog ? 1 : 0).setDuration(showDialogDuration).withStartAction(startAction).withEndAction(endAction).start();
    } else {
        if (!xAxis) {
            ViewCompat.setTranslationY(mGearLayoutWrapper, showDialog ? from : to);
            ViewCompat.animate(mGearLayoutWrapper).translationY(showDialog ? to : from).setDuration(showDialogDuration).withStartAction(startAction).withEndAction(endAction).start();
        } else {
            ViewCompat.setTranslationX(mGearLayoutWrapper, showDialog ? from : to);
            ViewCompat.animate(mGearLayoutWrapper).translationX(showDialog ? to : from).setDuration(showDialogDuration).withStartAction(startAction).withEndAction(endAction).start();
        }
    }

    ViewCompat.setAlpha(mMainBackground, showDialog ? 0 : isEnableBlur ? 1 : mMainBackgroundAlpha);
    ViewCompat.animate(mMainBackground).alpha(showDialog ? isEnableBlur ? 1 : mMainBackgroundAlpha : 0).setDuration(showDialogDuration).start();
}