Java Code Examples for android.view.View.setTranslationX()

The following are Jave code examples for showing how to use setTranslationX() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Carousel   File: DepthPageTransformer.java   Source Code and License Vote up 9 votes
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();

    if (position < -1) { // [-Infinity,-1)
        view.setAlpha(0);
    } else if (position <= 0) { // [-1,0]
        view.setAlpha(1);
        view.setTranslationX(0);
        view.setScaleX(1);
        view.setScaleY(1);
    } else if (position <= 1) { // (0,1]
        view.setAlpha(1 - position);
        view.setTranslationX(pageWidth * -position);
        float scaleFactor = MIN_SCALE
                + (1 - MIN_SCALE) * (1 - Math.abs(position));
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

    } else { // (1,+Infinity]
        view.setAlpha(0);
    }
}
 
Example 2
Project: ArcLayout-master   File: MainActivity.java   Source Code and License Vote up 8 votes
private Animator createShowItemAnimator(View item) {

        float dx = fab.getX() - item.getX();
        float dy = fab.getY() - item.getY();

        item.setRotation(0f);
        item.setTranslationX(dx);
        item.setTranslationY(dy);

        Animator anim = ObjectAnimator.ofPropertyValuesHolder(
                item,
//                AnimatorUtils.rotation(0f, 720f),
                AnimatorUtils.translationX(dx, 0f),
                AnimatorUtils.translationY(dy, 0f)
        );

        return anim;
    }
 
Example 3
Project: GitHub   File: ABaseTransformer.java   Source Code and License Vote up 7 votes
/**
	 * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)}.
	 * <p>
	 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
	 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
	 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
	 * alpha.
	 *
	 * @param page
	 *            Apply the transformation to this page
	 * @param position
	 *            Position of page relative to the current front-and-center position of the pager. 0 is front and
	 *            center. 1 is one full page position to the right, and -1 is one page position to the left.
	 */
	protected void onPreTransform(View page, float position) {
		final float width = page.getWidth();

		page.setRotationX(0);
		page.setRotationY(0);
		page.setRotation(0);
		page.setScaleX(1);
		page.setScaleY(1);
		page.setPivotX(0);
		page.setPivotY(0);
		page.setTranslationY(0);
		page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

		if (hideOffscreenPages()) {
			page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
//			page.setEnabled(false);
		} else {
//			page.setEnabled(true);
			page.setAlpha(1f);
		}
	}
 
Example 4
Project: boohee_v5.6   File: ZoomOutTranformer.java   Source Code and License Vote up 6 votes
protected void onTransform(View view, float position) {
    float scale = 1.0f + Math.abs(position);
    view.setScaleX(scale);
    view.setScaleY(scale);
    view.setPivotX(((float) view.getWidth()) * 0.5f);
    view.setPivotY(((float) view.getHeight()) * 0.5f);
    float f = (position < -1.0f || position > 1.0f) ? 0.0f : 1.0f - (scale - 1.0f);
    view.setAlpha(f);
    if (position == -1.0f) {
        view.setTranslationX((float) (view.getWidth() * -1));
    }
}
 
Example 5
Project: Mybilibili   File: ABaseTransformer.java   Source Code and License Vote up 6 votes
/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View, float)}.
 * <p>
 * The default implementation attempts to reset all view properties. This is useful when toggling transforms that do
 * not modify the same page properties. For instance changing from a transformation that applies rotation to a
 * transformation that fades can inadvertently leave a fragment stuck with a rotation or with some degree of applied
 * alpha.
 * 
 * @param page
 *            Apply the transformation to this page
 * @param position
 *            Position of page relative to the current front-and-center position of the pager. 0 is front and
 *            center. 1 is one full page position to the right, and -1 is one page position to the left.
 */
protected void onPreTransform(View page, float position) {
	final float width = page.getWidth();

	page.setRotationX(0);
	page.setRotationY(0);
	page.setRotation(0);
	page.setScaleX(1);
	page.setScaleY(1);
	page.setPivotX(0);
	page.setPivotY(0);
	page.setTranslationY(0);
	page.setTranslationX(isPagingEnabled() ? 0f : -width * position);

	if (hideOffscreenPages()) {
		page.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
	} else {
		page.setAlpha(1f);
	}
}
 
Example 6
Project: PageTransformerHelp   File: TabletTransformer.java   Source Code and License Vote up 6 votes
@Override
protected void onTransform(View view, float position) {
	final float rotation = (position < 0 ? 30f : -30f) * Math.abs(position);

	view.setTranslationX(getOffsetXForRotation(rotation, view.getWidth(), view.getHeight()));
	view.setPivotX(view.getWidth() * 0.5f);
	view.setPivotY(0);
	view.setRotationY(rotation);
}
 
Example 7
Project: chromium-for-android-56-debug-video   File: ContextualSearchPromoControl.java   Source Code and License Vote up 6 votes
/**
 * Shows the Promo Android View. By making the Android View visible, we are allowing the
 * Promo to be interactive. Since snapshots are not interactive (they are just a bitmap),
 * we need to temporarily show the Android View on top of the snapshot, so the user will
 * be able to click in the Promo buttons and/or link.
 */
private void showPromoView() {
    float y = getYPx();
    View view = getView();
    if (view == null
            || !mIsVisible
            || (mIsShowingView && mPromoViewY == y)
            || mHeightPx == 0.f) return;

    float offsetX = mOverlayPanel.getOffsetX() * mDpToPx;
    if (LocalizationUtils.isLayoutRtl()) {
        offsetX = -offsetX;
    }

    view.setTranslationX(offsetX);
    view.setTranslationY(y);
    view.setVisibility(View.VISIBLE);

    // NOTE(pedrosimonetti): We need to call requestLayout, otherwise
    // the Promo View will not become visible.
    view.requestLayout();

    mIsShowingView = true;
    mPromoViewY = y;

    // The Promo can only be interacted when the View is being displayed.
    mWasInteractive = true;
}
 
Example 8
Project: boohee_v5.6   File: TabletTransformer.java   Source Code and License Vote up 6 votes
protected void onTransform(View view, float position) {
    float rotation = (position < 0.0f ? 30.0f : -30.0f) * Math.abs(position);
    view.setTranslationX(getOffsetXForRotation(rotation, view.getWidth(), view.getHeight()));
    view.setPivotX(((float) view.getWidth()) * 0.5f);
    view.setPivotY(0.0f);
    view.setRotationY(rotation);
}
 
Example 9
Project: RNLearn_Project1   File: BaseViewManager.java   Source Code and License Vote up 6 votes
private static void resetTransformProperty(View view) {
  view.setTranslationX(PixelUtil.toPixelFromDIP(0));
  view.setTranslationY(PixelUtil.toPixelFromDIP(0));
  view.setRotation(0);
  view.setRotationX(0);
  view.setRotationY(0);
  view.setScaleX(1);
  view.setScaleY(1);
  view.setCameraDistance(0);
}
 
Example 10
Project: easlider   File: ZoomOutTransformer.java   Source Code and License Vote up 5 votes
@Override
protected void onTransform(View view, float position) {
    final float scale = 1f + Math.abs(position);
    view.setScaleX(scale);
    view.setScaleY(scale);
    view.setPivotX(view.getWidth() * 0.5f);
    view.setPivotY(view.getHeight() * 0.5f);
    view.setAlpha(position < -1f || position > 1f ? 0f : 1f - (scale - 1f));
    if (position == -1) {
        view.setTranslationX(view.getWidth() * -1);
    }
}
 
Example 11
Project: ColorBox-library   File: ZoomOutPageTransformer.java   Source Code and License Vote up 5 votes
public void transformPage(@NonNull View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();

    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setAlpha(0);

    } else if (position <= 1) { // [-1,1]
        // Modify the default slide transition to shrink the page as well
        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));

    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setAlpha(0);
    }
}
 
Example 12
Project: ImitateZHRB   File: ZoomOutSlideTransformer.java   Source Code and License 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 width = view.getWidth();
		final float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
		final float vertMargin = height * (1 - scaleFactor) / 2;
		final float horzMargin = width * (1 - scaleFactor) / 2;

		// Center vertically
		view.setPivotY(0.5f * height);
		view.setPivotX(0.5f * width);

		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));
	}
}
 
Example 13
Project: GxIconAndroid   File: SimplePageTransformer.java   Source Code and License Vote up 5 votes
private void transformPageDepth(View view, float position) {
    final float MIN_SCALE = 0.75f;

    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);
    }
}
 
Example 14
Project: VerticalViewPager   File: ZoomOutTransformer.java   Source Code and License Vote up 5 votes
@Override
public void transformPage(View view, float position) {
    int pageWidth = view.getWidth();
    int pageHeight = view.getHeight();
    float alpha = 0;
    if (0 <= position && position <= 1) {
        alpha = 1 - position;
    } else if (-1 < position && position < 0) {
        float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
        float verticalMargin = pageHeight * (1 - scaleFactor) / 2;
        float horizontalMargin = pageWidth * (1 - scaleFactor) / 2;
        if (position < 0) {
            view.setTranslationX(horizontalMargin - verticalMargin / 2);
        } else {
            view.setTranslationX(-horizontalMargin + verticalMargin / 2);
        }

        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);

        alpha = position + 1;
    }

    view.setAlpha(alpha);
    view.setTranslationX(view.getWidth() * -position);
    float yPosition = position * view.getHeight();
    view.setTranslationY(yPosition);
}
 
Example 15
Project: LuaViewPlayground   File: UDView.java   Source Code and License Vote up 5 votes
/**
 * č®¾ē½®Translation X, Y
 *
 * @param tx
 * @param ty
 * @return
 */
public UDView setTranslation(Float tx, Float ty) {
    final View view = getView();
    if (view != null) {
        if (tx != null) {
            view.setTranslationX(tx);
        }
        if (ty != null) {
            view.setTranslationY(ty);
        }
    }
    return this;
}
 
Example 16
Project: GitHub   File: RotateUpTransformer.java   Source Code and License Vote up 5 votes
@Override
protected void onTransform(View view, float position) {
	final float width = view.getWidth();
	final float rotation = ROT_MOD * position;

	view.setPivotX(width * 0.5f);
	view.setPivotY(0f);
	view.setTranslationX(0f);
	view.setRotation(rotation);
}
 
Example 17
Project: GitHub   File: StackTransformer.java   Source Code and License Vote up 4 votes
@Override
protected void onTransform(View view, float position) {
	view.setTranslationX(position < 0 ? 0f : -view.getWidth() * position);
}
 
Example 18
Project: boohee_v5.6   File: ViewCompatHC.java   Source Code and License Vote up 4 votes
public static void setTranslationX(View view, float value) {
    view.setTranslationX(value);
}
 
Example 19
Project: text_converter   File: FloatingView.java   Source Code and License Vote up 4 votes
private void adjustInactivePosition() {
    if (mRootView == null) return;
    if (DEBUG) {
        Log.d(TAG, String.format("adjustInactivePosition() mCurrentPosX=%s, mCurrentPosY=%s screenWidth=%s, screenHeight=%s",
                mCurrentPosX, mCurrentPosY, getScreenWidth(), getScreenHeight()));
    }

    mInactiveButton.setVisibility(View.VISIBLE);
    mRootView.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (mRootView != null && !mIsViewOpen) {
                mRootView.setVisibility(View.GONE);
            }
        }
    }, 30);

    // Our icon is made up of two parts. The outer shell, which uses mInactiveParams to position
    // itself within the phone screen's dimensions, and the inner shell, which uses translation
    // to slightly adjust the icon when it's supposed to appear slightly cropped
    int x = mCurrentPosX;
    int y = mCurrentPosY;
    View innerShell = mInactiveButton.getChildAt(0);
    innerShell.setTranslationX(0);
    innerShell.setTranslationY(0);

    if (x < 0) {
        innerShell.setTranslationX(x);
        x = 0;
    } else if (x > getScreenWidth() - mIconSize) {
        innerShell.setTranslationX(x - getScreenWidth() + mIconSize);
        x = getScreenWidth() - mIconSize;
    }
    if (DEBUG) {
        Log.d(TAG, "getTranslationX: " + innerShell.getTranslationX());
    }

    if (y < 0) {
        innerShell.setTranslationY(y);
        y = 0;
    } else if (y > getScreenHeight() - mIconSize) {
        innerShell.setTranslationY(y - getScreenHeight() + mIconSize);
        y = getScreenHeight() - mIconSize;
    }
    if (DEBUG) {
        Log.d(TAG, "getTranslationY: " + innerShell.getTranslationY());
    }

    mInactiveParams.x = x;
    mInactiveParams.y = y;
    if (!mIsDestroyed) mWindowManager.updateViewLayout(mInactiveButton, mInactiveParams);
}
 
Example 20
Project: grblcontroller   File: ReaderViewPagerTransformer.java   Source Code and License Vote up 4 votes
public void transformPage(View page, float position) {
    final float alpha;
    final float scale;
    final float translationX;

    switch (mTransformType) {
        case FLOW:
            page.setRotationY(position * -30f);
            return;

        case SLIDE_OVER:
            if (position < 0 && position > -1) {
                // this is the page to the left
                scale = Math.abs(Math.abs(position) - 1) * (1.0f - SCALE_FACTOR_SLIDE) + SCALE_FACTOR_SLIDE;
                alpha = Math.max(MIN_ALPHA_SLIDE, 1 - Math.abs(position));
                int pageWidth = page.getWidth();
                float translateValue = position * -pageWidth;
                if (translateValue > -pageWidth) {
                    translationX = translateValue;
                } else {
                    translationX = 0;
                }
            } else {
                alpha = 1;
                scale = 1;
                translationX = 0;
            }
            break;

        case DEPTH:
            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;
            }
            break;

        case ZOOM:
            if (position >= -1 && position <= 1) {
                scale = Math.max(MIN_SCALE_ZOOM, 1 - Math.abs(position));
                alpha = MIN_ALPHA_ZOOM +
                        (scale - MIN_SCALE_ZOOM) / (1 - MIN_SCALE_ZOOM) * (1 - MIN_ALPHA_ZOOM);
                float vMargin = page.getHeight() * (1 - scale) / 2;
                float hMargin = page.getWidth() * (1 - scale) / 2;
                if (position < 0) {
                    translationX = (hMargin - vMargin / 2);
                } else {
                    translationX = (-hMargin + vMargin / 2);
                }
            } else {
                alpha = 1;
                scale = 1;
                translationX = 0;
            }
            break;

        default:
            return;
    }

    page.setAlpha(alpha);
    page.setTranslationX(translationX);
    page.setScaleX(scale);
    page.setScaleY(scale);
}