Example usage for android.view View setTranslationX

List of usage examples for android.view View setTranslationX

Introduction

In this page you can find the example usage for android.view View setTranslationX.

Prototype

public void setTranslationX(float translationX) 

Source Link

Document

Sets the horizontal location of this view relative to its #getLeft() left position.

Usage

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.java

private void animateMenuItem(final MenuItem vEditSubkeys, final boolean animateShow) {

    View actionView = LayoutInflater.from(this).inflate(R.layout.edit_icon, null);
    vEditSubkeys.setActionView(actionView);
    actionView.setTranslationX(animateShow ? 150 : 0);

    ViewPropertyAnimator animator = actionView.animate();
    animator.translationX(animateShow ? 0 : 150);
    animator.setDuration(300);//www.  java 2 s  . c  om
    animator.setInterpolator(new OvershootInterpolator(1.5f));
    animator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!animateShow) {
                vEditSubkeys.setVisible(false);
            }
            vEditSubkeys.setActionView(null);
        }
    });
    animator.start();

}

From source file:cn.lanmei.com.dingdong_2.ItemDecoration.StickyHeaderDecoration.java

/**
 * {@inheritDoc}//from   w  ww.j  a  va2 s  . co m
 */
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    //        final int count = parent.getChildCount();
    LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter();
    RecyclerView.Adapter ra = adapter.getInnerAdapter();
    final int count = ra.getItemCount();

    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);

        final int adapterPos = parent.getChildAdapterPosition(child);

        //            L.MyLog("sticky","onDrawOver:"+adapterPos+"getItemCount"+count);
        if (adapterPos != RecyclerView.NO_POSITION && (layoutPos == 0 || hasHeader(adapterPos))) {

            View header = getHeader(parent, adapterPos).itemView;
            c.save();
            final int left = child.getLeft();
            final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
            c.translate(left, top);
            header.setTranslationX(left);
            header.setTranslationY(top);
            header.draw(c);
            c.restore();
        }
    }
}

From source file:me.xiaopan.android.widget.DepthPageTransformer.java

@SuppressLint("NewApi")
@Override//from w w  w . j  a  v  a  2  s .c  o m
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    if (position < -1) { // [-Infinity,-1)
                         // This page is way off-screen to the left.
        view.setAlpha(0);
    } else if (position <= 0) { // [-1,0]
                                // Use the default slide transition when
                                // moving to the left page
        view.setAlpha(1);
        view.setTranslationX(0);
        view.setScaleX(1);
        view.setScaleY(1);
    } else if (position <= 1) { // (0,1]
                                // Fade the page out.
        view.setAlpha(1 - position);
        // Counteract the default slide transition
        view.setTranslationX(pageWidth * -position);
        // Scale the page down (between MIN_SCALE and 1)
        float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);
    } else { // (1,+Infinity]
             // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}

From source file:net.dewep.intranetepitech.animation.ZoomOutPageTransformer.java

private void positionPositive(View view, float position) {
    // [-1,1]/*w ww  .  j a  va 2s.  c  o m*/
    // Modify the default slide transition to shrink the page as well
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();
    float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
    float vertMargin = pageHeight * (1 - scaleFactor) / 2;
    float horzMargin = pageWidth * (1 - scaleFactor) / 2;
    if (position < 0) {
        view.setTranslationX(horzMargin - vertMargin / 2);
    } else {
        view.setTranslationX(-horzMargin + vertMargin / 2);
    }
    // Scale the page down (between MIN_SCALE and 1)
    view.setScaleX(scaleFactor);
    view.setScaleY(scaleFactor);
    // Fade the page relative to its size.
    view.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
}

From source file:com.chartiq.chartiqsample.ui.StickyHeaderDecoration.java

/**
 * {@inheritDoc}/*from  ww w .j av  a  2 s.  c  om*/
 */
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    final int count = parent.getChildCount();
    long previousHeaderId = -1;

    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        final int adapterPos = parent.getChildAdapterPosition(child);
        if (child.getVisibility() == View.GONE) {
            continue;
        }

        if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) {
            long headerId = mAdapter.getHeaderId(adapterPos);

            if (headerId != previousHeaderId) {
                previousHeaderId = headerId;
                View header = getHeader(parent, adapterPos).itemView;
                canvas.save();

                final int left = child.getLeft();
                final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
                canvas.translate(left, top);

                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(canvas);
                canvas.restore();
            }
        }
    }
}

From source file:ca.barrenechea.widget.recyclerview.decoration.StickyHeaderDecoration.java

/**
 * {@inheritDoc}/* w  ww.  j  av a2 s.  c o  m*/
 */
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    final int count = parent.getChildCount();
    long previousHeaderId = -1;

    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        final int adapterPos = parent.getChildAdapterPosition(child);

        if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) {
            long headerId = mAdapter.getHeaderId(adapterPos);

            if (headerId != previousHeaderId) {
                previousHeaderId = headerId;
                View header = getHeader(parent, adapterPos).itemView;
                canvas.save();

                final int left = child.getLeft();
                final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
                canvas.translate(left, top);

                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(canvas);
                canvas.restore();
            }
        }
    }
}

From source file:com.dat.complexrecyclerviewdemo.recyclerviewinsidecardviewdemo.StickyHeaderDecoration.java

/**
 * {@inheritDoc}// ww  w.  j a va2  s . c o  m
 */
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    final int count = parent.getChildCount();
    long previousHeaderId = -1;

    for (int layoutPos = 0; layoutPos < count; layoutPos++) {
        final View child = parent.getChildAt(layoutPos);
        final int adapterPos = parent.getChildAdapterPosition(child);

        if (adapterPos != RecyclerView.NO_POSITION && hasHeader(adapterPos)) {
            long headerId = mAdapter.getHeaderId(adapterPos);

            if (headerId != previousHeaderId) {
                previousHeaderId = headerId;
                View header = getHeader(parent, adapterPos).itemView;
                canvas.save();

                final int left = child.getLeft();
                final int top = getHeaderTop(parent, child, header, adapterPos, layoutPos);
                canvas.translate(left, top - 4);
                header.setTranslationX(left);
                header.setTranslationY(top);
                header.draw(canvas);
                canvas.restore();
            }
        }
    }
}

From source file:com.flexible.flexibleadapter.helpers.StickyHeaderHelper.java

private void resetHeader(FlexibleViewHolder header) {
    restoreHeaderItemVisibility();//from   www  . jav  a 2s  . c  o m
    // Clean the header container
    final View view = header.getContentView();
    removeViewFromParent(view);
    // Reset translation on removed header
    view.setTranslationX(0);
    view.setTranslationY(0);
    if (!header.itemView.equals(view))
        ((ViewGroup) header.itemView).addView(view);
    header.setIsRecyclable(true);
    // #294 - Expandable header is not resized / redrawn on automatic configuration change when sticky headers are enabled
    header.itemView.getLayoutParams().width = view.getLayoutParams().width;
    header.itemView.getLayoutParams().height = view.getLayoutParams().height;
}

From source file:eu.davidea.flexibleadapter.helpers.StickyHeaderHelper.java

private void resetHeader(FlexibleViewHolder header) {
    restoreHeaderItemVisibility();/*from  w w w.  j  a  v  a 2s.  co m*/
    // Clean the header container
    final View view = header.getContentView();
    removeViewFromParent(view);
    // Reset translation on removed header
    view.setTranslationX(0);
    view.setTranslationY(0);
    if (!header.itemView.equals(view))
        ((ViewGroup) header.itemView).addView(view);
    header.setIsRecyclable(true);
}

From source file:com.android.clear.reminder.ItemAnimator.java

@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    endAnimation(holder);//from  w w w  .jav a 2 s  . c o m

    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    final long moveDuration = getMoveDuration();

    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }

    final View view = holder.itemView;
    final float prevTranslationX = view.getTranslationX();
    final float prevTranslationY = view.getTranslationY();
    view.setTranslationX(-deltaX);
    view.setTranslationY(-deltaY);

    final ObjectAnimator moveAnimator;
    if (deltaX != 0 && deltaY != 0) {
        final PropertyValuesHolder moveX = PropertyValuesHolder.ofFloat(TRANSLATION_X, 0f);
        final PropertyValuesHolder moveY = PropertyValuesHolder.ofFloat(TRANSLATION_Y, 0f);
        moveAnimator = ObjectAnimator.ofPropertyValuesHolder(holder.itemView, moveX, moveY);
    } else if (deltaX != 0) {
        final PropertyValuesHolder moveX = PropertyValuesHolder.ofFloat(TRANSLATION_X, 0f);
        moveAnimator = ObjectAnimator.ofPropertyValuesHolder(holder.itemView, moveX);
    } else {
        final PropertyValuesHolder moveY = PropertyValuesHolder.ofFloat(TRANSLATION_Y, 0f);
        moveAnimator = ObjectAnimator.ofPropertyValuesHolder(holder.itemView, moveY);
    }

    moveAnimator.setDuration(moveDuration);
    moveAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);
    moveAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animator.removeAllListeners();
            mAnimators.remove(holder);
            view.setTranslationX(prevTranslationX);
            view.setTranslationY(prevTranslationY);
            dispatchMoveFinished(holder);
        }
    });
    mMoveAnimatorsList.add(moveAnimator);
    mAnimators.put(holder, moveAnimator);

    return true;
}