Java Code Examples for com.nineoldandroids.view.ViewHelper#setTranslationX()
The following examples show how to use
com.nineoldandroids.view.ViewHelper#setTranslationX() .
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 |
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: DragLayout.java From MyHearts with Apache License 2.0 | 6 votes |
/** * 根据滑动的距离的比例,进行带有动画的缩小和放大View * * @param percent */ private void animateView(float percent) { float f1 = 1 - percent * 0.3f; //vg_main水平方向 根据百分比缩放 ViewHelper.setScaleX(vg_main, f1); //vg_main垂直方向,根据百分比缩放 ViewHelper.setScaleY(vg_main, f1); //沿着水平X轴平移 ViewHelper.setTranslationX(vg_left, -vg_left.getWidth() / 2.3f + vg_left.getWidth() / 2.3f * percent); //vg_left水平方向 根据百分比缩放 ViewHelper.setScaleX(vg_left, 0.5f + 0.5f * percent); //vg_left垂直方向 根据百分比缩放 ViewHelper.setScaleY(vg_left, 0.5f + 0.5f * percent); //vg_left根据百分比进行设置透明度 ViewHelper.setAlpha(vg_left, percent); if (isShowShadow) { //阴影效果视图大小进行缩放 ViewHelper.setScaleX(iv_shadow, f1 * 1.4f * (1 - percent * 0.12f)); ViewHelper.setScaleY(iv_shadow, f1 * 1.85f * (1 - percent * 0.12f)); } getBackground().setColorFilter(evaluate(percent, Color.BLACK, Color.TRANSPARENT), Mode.SRC_OVER); }
Example 3
Source File: DepthTransformer.java From FlycoBanner_Master with MIT License | 6 votes |
@Override public void transformPage(View page, float position) { float alpha, scale, translationX; if (position > 0 && position < 1) { // moving to the right alpha = (1 - position); scale = MIN_SCALE_DEPTH + (1 - MIN_SCALE_DEPTH) * (1 - Math.abs(position)); translationX = (page.getWidth() * -position); } else { // use default for all other cases alpha = 1; scale = 1; translationX = 0; } ViewHelper.setAlpha(page, alpha); ViewHelper.setTranslationX(page, translationX); ViewHelper.setScaleX(page, scale); ViewHelper.setScaleY(page, scale); }
Example 4
Source File: JazzyViewPager.java From JazzyViewPager with Apache License 2.0 | 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 5
Source File: TabletTransformer.java From UltimateAndroid with Apache License 2.0 | 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 6
Source File: ProductTour2Activity.java From ProductTour with Apache License 2.0 | 5 votes |
@Override public void transformPage(View page, float position) { int pageWidth = page.getWidth(); View backgroundView = page.findViewById(R.id.welcome_fragment); View text_head= page.findViewById(R.id.heading); View text_content = page.findViewById(R.id.content); if(0 <= position && position < 1){ ViewHelper.setTranslationX(page,pageWidth * -position); } if(-1 < position && position < 0){ ViewHelper.setTranslationX(page,pageWidth * -position); } if(position <= -1.0f || position >= 1.0f) { } else if( position == 0.0f ) { } else { if(backgroundView != null) { ViewHelper.setAlpha(backgroundView,1.0f - Math.abs(position)); } if (text_head != null) { ViewHelper.setTranslationX(text_head,pageWidth * position); ViewHelper.setAlpha(text_head,1.0f - Math.abs(position)); } if (text_content != null) { ViewHelper.setTranslationX(text_content,pageWidth * position); ViewHelper.setAlpha(text_content,1.0f - Math.abs(position)); } } }
Example 7
Source File: JazzyViewPager.java From UltimateAndroid with Apache License 2.0 | 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 8
Source File: ZoomOutTransformer.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override protected void onTransform(View view, float position) { final float scale = 1f + Math.abs(position); ViewHelper.setScaleX(view,scale); ViewHelper.setScaleY(view,scale); ViewHelper.setPivotX(view,view.getWidth() * 0.5f); ViewHelper.setPivotY(view,view.getWidth() * 0.5f); ViewHelper.setAlpha(view,position < -1f || position > 1f ? 0f : 1f - (scale - 1f)); if(position < -0.9){ //-0.9 to prevent a small bug ViewHelper.setTranslationX(view,view.getWidth() * position); } }
Example 9
Source File: PullLayout.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
private void animatePull(int t) { mTopRL.getLayoutParams().height = mRange - t; mTopRL.requestLayout(); float percent = (float) t / mRange; ViewHelper.setScaleX(mEV, 1 - percent); ViewHelper.setScaleY(mEV, 1 - percent); ViewHelper.setScaleX(mTV, 2 - percent); ViewHelper.setScaleY(mTV, 2 - percent); ViewHelper.setTranslationX(mTV, mTVWidth * (1 - percent) / 2f); ViewHelper.setTranslationY(mWeaterLL, t / 2); }
Example 10
Source File: RotateUpTransformer.java From AndroidImageSlider with MIT License | 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 11
Source File: JazzyViewPager.java From android-kernel-tweaker with GNU General Public License v3.0 | 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 12
Source File: JazzyViewPager.java From Contacts with MIT License | 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 13
Source File: JazzyViewPager.java From zhangshangwuda with Apache License 2.0 | 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 14
Source File: JazzyViewPager.java From school_shop with MIT License | 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 15
Source File: FlexibleSpaceWithImageGridViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
@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, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0)); ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0)); // Translate list background ViewHelper.setTranslationY(mListBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight)); // Change alpha of overlay ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat((flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); setPivotXToTitle(); 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; ViewHelper.setTranslationY(mTitleView, titleTranslationY); // Translate FAB int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2; float fabTranslationY = ScrollUtils.getFloat( -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2, mActionBarSize - mFab.getHeight() / 2, maxFabTranslationY); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin, // which causes FAB's OnClickListener not working. FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams(); lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth(); lp.topMargin = (int) fabTranslationY; mFab.requestLayout(); } else { ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth()); ViewHelper.setTranslationY(mFab, fabTranslationY); } // Show/hide FAB if (fabTranslationY < mFlexibleSpaceShowFabOffset) { hideFab(); } else { showFab(); } }
Example 16
Source File: FlexibleSpaceWithImageScrollViewActivity.java From UltimateAndroid with Apache License 2.0 | 4 votes |
@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); } } }
Example 17
Source File: ParallaxViewHolder.java From AndroidParallax with Apache License 2.0 | 4 votes |
public void onParallax(int offset) { if (parallaxY != null) ViewHelper.setTranslationY(view, offset * parallaxY); if (parallaxX != null) ViewHelper.setTranslationX(view, offset * parallaxX); }
Example 18
Source File: FloatingActionItemImageView.java From android-floating-action-menu with Apache License 2.0 | 4 votes |
public void hide(boolean animate, int delay) { if (LOG_ENABLED) { Log.i(TAG, "hide, current status: " + mStatus); Log.v(TAG, "direction: " + direction); Log.v(TAG, "animate: " + animate); } if (mStatus == Status.Invisible) { if (LOG_ENABLED) { Log.w(TAG, "already hidden"); } return; } mStatus = Status.Animating; if (mShowAnimator.isStarted()) { mShowAnimator.cancel(); } if (mHideAnimator.isStarted()) { mHideAnimator.cancel(); } if (direction == FloatingActionMenu.Direction.Vertical) { if (!animate) { ViewHelper.setTranslationY(this, y2); onAnimationEnd(ANIMATION_HIDE); } else { if (ApiHelper.AT_LEAST_11) { mHideAnimator.setFloatValues(y2); } else { mHideAnimator.setFloatValues(y1, y2); } mHideAnimator.setStartDelay(delay); mHideAnimator.start(); } } else { if (!animate) { ViewHelper.setTranslationX(this, x2); onAnimationEnd(ANIMATION_HIDE); } else { if (ApiHelper.AT_LEAST_11) { mHideAnimator.setFloatValues(x2); } else { mHideAnimator.setFloatValues(x1, x2); } mHideAnimator.setStartDelay(delay); mHideAnimator.start(); } } }
Example 19
Source File: FlipPageViewTransformer.java From AndroidImageSlider with MIT License | 4 votes |
private void setTranslation(View view) { ViewPagerEx viewPager = (ViewPagerEx) view.getParent(); int scroll = viewPager.getScrollX() - view.getLeft(); ViewHelper.setTranslationX(view,scroll); }
Example 20
Source File: SwipeTouchListener.java From ListViewAnimations with Apache License 2.0 | 2 votes |
/** * Restores the {@link android.view.View}'s {@code alpha} and {@code translationX} values. * Users of this class should call this method when recycling {@code View}s. * * @param view the {@code View} whose presentation should be restored. */ protected void restoreViewPresentation(@NonNull final View view) { View swipedView = getSwipeView(view); ViewHelper.setAlpha(swipedView, 1); ViewHelper.setTranslationX(swipedView, 0); }