Java Code Examples for com.nineoldandroids.view.ViewHelper.setTranslationX()

The following are Jave code examples for showing how to use setTranslationX() of the com.nineoldandroids.view.ViewHelper class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: JewelryUI   File: JazzyViewPager.java   View Source Code Vote up 6 votes
protected void animateTablet(View left, View right, float positionOffset) {		
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 30.0f * positionOffset;
			mTrans = getOffsetXForRotation(mRot, left.getMeasuredWidth(),
					left.getMeasuredHeight());
			ViewHelper.setPivotX(left, left.getMeasuredWidth()/2);
			ViewHelper.setPivotY(left, left.getMeasuredHeight()/2);
			ViewHelper.setTranslationX(left, mTrans);
			ViewHelper.setRotationY(left, mRot);
			logState(left, "Left");
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -30.0f * (1-positionOffset);
			mTrans = getOffsetXForRotation(mRot, right.getMeasuredWidth(), 
					right.getMeasuredHeight());
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setTranslationX(right, mTrans);
			ViewHelper.setRotationY(right, mRot);
			logState(right, "Right");
		}
	}
}
 
Example 2
Project: JewelryUI   File: JazzyViewPager.java   View Source Code Vote up 6 votes
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 3
Project: JazzyViewPager   File: JazzyViewPager.java   View Source Code Vote up 6 votes
protected void animateTablet(View left, View right, float positionOffset) {		
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 30.0f * positionOffset;
			mTrans = getOffsetXForRotation(mRot, left.getMeasuredWidth(),
					left.getMeasuredHeight());
			ViewHelper.setPivotX(left, left.getMeasuredWidth()/2);
			ViewHelper.setPivotY(left, left.getMeasuredHeight()/2);
			ViewHelper.setTranslationX(left, mTrans);
			ViewHelper.setRotationY(left, mRot);
			logState(left, "Left");
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -30.0f * (1-positionOffset);
			mTrans = getOffsetXForRotation(mRot, right.getMeasuredWidth(), 
					right.getMeasuredHeight());
			ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
			ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
			ViewHelper.setTranslationX(right, mTrans);
			ViewHelper.setRotationY(right, mRot);
			logState(right, "Right");
		}
	}
}
 
Example 4
Project: JazzyViewPager   File: JazzyViewPager.java   View Source Code Vote up 5 votes
private void animateFlipVertical(View left, View right, float positionOffset, int positionOffsetPixels) {
	if(mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 180.0f * positionOffset;
			if (mRot > 90.0f) {
				left.setVisibility(View.INVISIBLE);
			} else {
				if (left.getVisibility() == View.INVISIBLE)
					left.setVisibility(View.VISIBLE);
				mTrans = positionOffsetPixels;
				ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
				ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
				ViewHelper.setTranslationX(left, mTrans);
				ViewHelper.setRotationX(left, mRot);
			}
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -180.0f * (1-positionOffset);
			if (mRot < -90.0f) {
				right.setVisibility(View.INVISIBLE);
			} else {
				if (right.getVisibility() == View.INVISIBLE)
					right.setVisibility(View.VISIBLE);
				mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
				ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
				ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
				ViewHelper.setTranslationX(right, mTrans);
				ViewHelper.setRotationX(right, mRot);
			}
		}
	}
}
 
Example 5
Project: GongXianSheng   File: BaseViewAnimator.java   View Source Code Vote up 5 votes
/**
 * reset the view to default status
 *
 * @param target
 */
public 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 6
Project: MyAnimeViewer   File: BaseItemAnimator.java   View Source Code Vote up 5 votes
public static void clear(View v) {
    ViewHelper.setAlpha(v, 1);
    ViewHelper.setScaleY(v, 1);
    ViewHelper.setScaleX(v, 1);
    ViewHelper.setTranslationY(v, 0);
    ViewHelper.setTranslationX(v, 0);
    ViewHelper.setRotation(v, 0);
    ViewHelper.setRotationY(v, 0);
    ViewHelper.setRotationX(v, 0);
    // @TODO https://code.google.com/p/android/issues/detail?id=80863
    //        ViewHelper.setPivotY(v, v.getMeasuredHeight() / 2);
    v.setPivotY(v.getMeasuredHeight() / 2);
    ViewHelper.setPivotX(v, v.getMeasuredWidth() / 2);
    ViewPropertyAnimator.animate(v).setInterpolator(null);
}
 
Example 7
Project: JazzyViewPager   File: JazzyViewPager.java   View Source Code Vote up 5 votes
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 8
Project: JazzyViewPager   File: JazzyViewPager.java   View Source Code Vote up 5 votes
private void animateFlipHorizontal(View left, View right, float positionOffset, int positionOffsetPixels) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 180.0f * positionOffset;
			if (mRot > 90.0f) {
				left.setVisibility(View.INVISIBLE);
			} else {
				if (left.getVisibility() == View.INVISIBLE)
					left.setVisibility(View.VISIBLE);
				mTrans = positionOffsetPixels;
				ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
				ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
				ViewHelper.setTranslationX(left, mTrans);
				ViewHelper.setRotationY(left, mRot);
			}
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -180.0f * (1-positionOffset);
			if (mRot < -90.0f) {
				right.setVisibility(View.INVISIBLE);
			} else {
				if (right.getVisibility() == View.INVISIBLE)
					right.setVisibility(View.VISIBLE);
				mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
				ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
				ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
				ViewHelper.setTranslationX(right, mTrans);
				ViewHelper.setRotationY(right, mRot);
			}
		}
	}
}
 
Example 9
Project: Sega   File: TabletTransformer.java   View Source Code Vote up 5 votes
@Override
protected void onTransform(View view, float position) {
	final float rotation = (position < 0 ? 30f : -30f) * Math.abs(position);

	ViewHelper.setTranslationX(view,getOffsetXForRotation(rotation, view.getWidth(), view.getHeight()));
       ViewHelper.setPivotX(view,view.getWidth() * 0.5f);
       ViewHelper.setPivotY(view,0);
       ViewHelper.setRotationY(view,rotation);
}
 
Example 10
Project: TestChat   File: DragLayout.java   View Source Code Vote up 5 votes
/**
                 * 子view拖拽过程中位置改变的回调
                 *
                 * @param changedView 被拖拽的子view
                 * @param left        距离父布局左边的距离
                 * @param top         距离父布局上面的距离
                 * @param dx          x方向的偏移量
                 * @param dy          y方向的偏移量
                 */
                @Override
                public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
                        if (dx == 0) {
                                return;
                        }
                        if (changedView.equals(menu)) {
//                                如果拖拽的是menu,布局不变
                                menu.layout(0, 0, width, height);
//                                content.layout(marginLeft, 0, marginLeft + width, height);
//                                这里如果在屏幕上手指按定,就会出现dx=0,dy=1的情况
                                content.layout(left, 0, left + width, height);
                        }
//                                如果是内容布局,就随拖拽位移而变化,因为在smoothSlideViewTo中会进行控件边缘和内容边缘之间的移动,所以这里content要随时改变布局
//                                content.layout(marginLeft, 0, marginLeft + width, height);
//                        0~~1之间
                        float percent = left / (float) range;
                        float desWidth = (float) (width / 4.0 * (percent - 1));
//                        进行内容移动,本身控件位置不变
                        ViewHelper.setTranslationX(menu, desWidth);
                        if (SHADOW) {
//                                ivShadow.layout(marginLeft, 0, marginLeft + width, height);
                                ivShadow.layout(left, 0, left + width, height);
//                                ivShadow.setAlpha(percent * 225);
//                                ViewHelper.setAlpha(ivShadow, percent * 255);
//                                阴影效果
                                float f1 = 1 - percent * 0.5f;
                                ViewHelper.setScaleX(ivShadow, f1 * 1.2f * (1 - percent * 0.10f));
                                ViewHelper.setScaleY(ivShadow, f1 * 1.85f * (1 - percent * 0.10f));
                        }
                        int dragState = getCurrentState();
                        if (dragState == DRAG_STATE_OPEN) {
                                if (mListener != null) {
                                        mListener.onOpenMenu();
                                }
                        } else if (dragState == DRAG_STATE_CLOSE) {
                                if (mListener != null) {
                                        mListener.onCloseMenu();
                                }
                        } else {
                                if (mListener != null) {
                                        mListener.onDrag(changedView, percent);
                                }
                        }
                }
 
Example 11
Project: Hitalk   File: ImagePagerFragment.java   View Source Code Vote up 5 votes
/**
 * 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 12
Project: JewelryUI   File: JazzyViewPager.java   View Source Code Vote up 5 votes
private void animateFlipHorizontal(View left, View right, float positionOffset, int positionOffsetPixels) {
	if (mState != State.IDLE) {
		if (left != null) {
			manageLayer(left, true);
			mRot = 180.0f * positionOffset;
			if (mRot > 90.0f) {
				left.setVisibility(View.INVISIBLE);
			} else {
				if (left.getVisibility() == View.INVISIBLE)
					left.setVisibility(View.VISIBLE);
				mTrans = positionOffsetPixels;
				ViewHelper.setPivotX(left, left.getMeasuredWidth()*0.5f);
				ViewHelper.setPivotY(left, left.getMeasuredHeight()*0.5f);
				ViewHelper.setTranslationX(left, mTrans);
				ViewHelper.setRotationY(left, mRot);
			}
		}
		if (right != null) {
			manageLayer(right, true);
			mRot = -180.0f * (1-positionOffset);
			if (mRot < -90.0f) {
				right.setVisibility(View.INVISIBLE);
			} else {
				if (right.getVisibility() == View.INVISIBLE)
					right.setVisibility(View.VISIBLE);
				mTrans = -getWidth()-getPageMargin()+positionOffsetPixels;
				ViewHelper.setPivotX(right, right.getMeasuredWidth()*0.5f);
				ViewHelper.setPivotY(right, right.getMeasuredHeight()*0.5f);
				ViewHelper.setTranslationX(right, mTrans);
				ViewHelper.setRotationY(right, mRot);
			}
		}
	}
}
 
Example 13
Project: PhotoPicker-master   File: ImagePagerFragment.java   View Source Code Vote up 5 votes
/**
 * 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 14
Project: Widgets   File: SlideLayout.java   View Source Code Vote up 5 votes
/**
     * 伴随动画
     *
     * @return 当前滑动的比例
     */
    private float animViews() {
        float percent = mSlideDx * 1.0f / mSlideRang;

        // 左面板: 缩放动画, 平移动画, 透明度动画
//        ViewHelper.setScaleX(mLeftView, 0.4f + 0.4f * percent);
//        ViewHelper.setScaleY(mLeftView, 0.4f + 0.4f * percent);
        ViewHelper.setScaleX(mLeftView, evaluate(percent, 0.4f, 1.0f));
        ViewHelper.setScaleY(mLeftView, evaluate(percent, 0.4f, 1.0f));
        // 平移动画: -mWidth / 2.0f -> 0.0f
        ViewHelper.setTranslationX(mLeftView, evaluate(percent, -mWidth / 2.0f, 0));
        // 透明度: 0.4 -> 1.0f
        ViewHelper.setAlpha(mLeftView, evaluate(percent, 0.4f, 1.0f));

        // 主面板: 缩放动画  1.0f -> 0.8f
        ViewHelper.setScaleX(mMainView, evaluate(percent, 1.0f, 0.8f));
        ViewHelper.setScaleY(mMainView, evaluate(percent, 1.0f, 0.8f));

        // 透明度: 1.0 -> 0.6f
        if (mMainAlphaEnable) {
            ViewHelper.setAlpha(mMainView, evaluate(percent, 1.0f, 0.6f));
        }

        // 整个控件的背景动画: 亮度变化 (颜色变化)
        if (null != getBackground()) {
            getBackground().setColorFilter((Integer) evaluateColor(percent, mAlphaColor, Color.TRANSPARENT), PorterDuff.Mode.SRC_OVER);
        }

        return percent;
    }
 
Example 15
Project: Sega   File: DepthPageTransformer.java   View Source Code Vote up 5 votes
@Override
protected void onTransform(View view, float position) {
	if (position <= 0f) {
           ViewHelper.setTranslationX(view,0f);
           ViewHelper.setScaleX(view,1f);
           ViewHelper.setScaleY(view,1f);
	} else if (position <= 1f) {
		final float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
           ViewHelper.setAlpha(view,1-position);
           ViewHelper.setPivotY(view,0.5f * view.getHeight());
           ViewHelper.setTranslationX(view,view.getWidth() * - position);
           ViewHelper.setScaleX(view,scaleFactor);
           ViewHelper.setScaleY(view,scaleFactor);
	}
}
 
Example 16
Project: Sega   File: ForegroundToBackgroundTransformer.java   View Source Code Vote up 5 votes
@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 17
Project: Sega   File: BackgroundToForegroundTransformer.java   View Source Code Vote up 5 votes
@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 18
Project: Sega   File: RotateUpTransformer.java   View Source Code Vote up 5 votes
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float rotation = ROT_MOD * position;

	ViewHelper.setPivotX(view,width * 0.5f);
       ViewHelper.setPivotY(view,0f);
       ViewHelper.setTranslationX(view,0f);
       ViewHelper.setRotation(view,rotation);
}
 
Example 19
Project: Sega   File: ZoomOutSlideTransformer.java   View Source Code Vote up 5 votes
@Override
protected void onTransform(View view, float position) {
	if (position >= -1 || position <= 1) {
		// Modify the default slide transition to shrink the page as well
		final float height = view.getHeight();
		final float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
		final float vertMargin = height * (1 - scaleFactor) / 2;
		final float horzMargin = view.getWidth() * (1 - scaleFactor) / 2;

           // Center vertically
           ViewHelper.setPivotY(view,0.5f * height);


		if (position < 0) {
               ViewHelper.setTranslationX(view,horzMargin - vertMargin / 2);
		} else {
               ViewHelper.setTranslationX(view,-horzMargin + vertMargin / 2);
		}

		// Scale the page down (between MIN_SCALE and 1)
		ViewHelper.setScaleX(view,scaleFactor);
           ViewHelper.setScaleY(view,scaleFactor);

		// Fade the page relative to its size.
           ViewHelper.setAlpha(view,MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
	}
}
 
Example 20
Project: MenuSet   File: MenuAdapter.java   View Source Code Vote up 4 votes
/**
 * Set starting params to text animations
 */
private void resetTextAnimation(View v) {
    ViewHelper.setAlpha(v, !mIsMenuOpen ? 0 : 1);
    ViewHelper.setTranslationX(v, !mIsMenuOpen ? mMenuItemSize : 0);
}