Java Code Examples for android.view.View#setScaleX()

The following examples show how to use android.view.View#setScaleX() . 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: ZoomOutSlideTransformer.java    From android-viewpager-transformers with Apache License 2.0 6 votes vote down vote up
@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
		view.setPivotY(0.5f * height);

		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 2
Source File: BaseTransformer.java    From android-viewpager-transformers with Apache License 2.0 6 votes vote down vote up
/**
 * Called each {@link #transformPage(android.view.View, float)} before {{@link #onTransform(android.view.View, float)} is called.
 *
 * @param view
 * @param position
 */
protected void onPreTransform(View view, float position) {
	final float width = view.getWidth();

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

	if (hideOffscreenPages()) {
		view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
	} else {
		view.setAlpha(1f);
	}
}
 
Example 3
Source File: PassphraseAvatarTransformation.java    From adamant-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void transformItem(View item, float position) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView avatarView = item.findViewById(R.id.list_item_passphrase_avatar);

        float translationZ = (float) Math.abs(SELECTED_TRANSLATION_Z - ((Math.pow(2, Math.abs(position)) - 1) * SELECTED_TRANSLATION_Z));
        avatarView.setTranslationZ(translationZ);
    }

    pivotX.setOn(item);
    pivotY.setOn(item);
    float closenessToCenter = 1f - Math.abs(position);
    float scale = minScale + maxMinDiff * closenessToCenter;
    item.setScaleX(scale);
    item.setScaleY(scale);
}
 
Example 4
Source File: ZoomOutPageTransformer.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public void transformPage(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 5
Source File: ForegroundToBackgroundTransformer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@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);

	view.setScaleX(scale);
	view.setScaleY(scale);
	view.setPivotX(width * 0.5f);
	view.setPivotY(height * 0.5f);
	view.setTranslationX(position > 0 ? width * position : -width * position * 0.25f);
}
 
Example 6
Source File: ForegroundToBackgroundTransformer.java    From WanAndroid with GNU General Public License v3.0 5 votes vote down vote up
@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);

	view.setScaleX(scale);
	view.setScaleY(scale);
	view.setPivotX(width * 0.5f);
	view.setPivotY(height * 0.5f);
	view.setTranslationX(position > 0 ? width * position : -width * position * 0.25f);
}
 
Example 7
Source File: DepthPageTransformer.java    From newsApp with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: EnterOvershootAnimator.java    From FragmentMaster with Apache License 2.0 5 votes vote down vote up
@Override
protected void transformForegroundPage(View page, float position,
                                       boolean enter) {
    float offset = 0;
    if (enter) {
        // Perform overshot animation if enter.
        offset = page.getWidth()
                * ((1 - position) - sInterpolator
                .getInterpolation(1 - position));
    }
    page.setTranslationX(offset);
    page.setAlpha(1);
    page.setScaleX(1);
    page.setScaleY(1);
}
 
Example 9
Source File: CardStreamLinearLayout.java    From android-BatchStepSensor with Apache License 2.0 5 votes vote down vote up
private void resetAnimatedView(View child) {
    child.setAlpha(1.f);
    child.setTranslationX(0.f);
    child.setTranslationY(0.f);
    child.setRotation(0.f);
    child.setRotationY(0.f);
    child.setRotationX(0.f);
    child.setScaleX(1.f);
    child.setScaleY(1.f);
}
 
Example 10
Source File: AcDisplayFragment.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the visibility of divider between
 * the scene and icons.
 */
@SuppressLint("NewApi")
private void updateDividerVisibility(boolean animate) {
    final View view = mDividerView;

    final boolean visible = view.getVisibility() == View.VISIBLE;
    final boolean visibleNow = !mWidgetsMap.isEmpty();

    if (animate && isAnimatable()) {
        int visibleInt = MathUtils.bool(visible);
        int visibleNowInt = MathUtils.bool(visibleNow);
        float[] values = {1.0f, 0.1f, 1.0f, 0.5f};

        ViewUtils.setVisible(view, true);
        view.setScaleX(values[1 - visibleInt]);
        view.setAlpha(values[3 - visibleInt]);
        view.animate()
                .scaleX(values[1 - visibleNowInt])
                .alpha(values[3 - visibleNowInt])
                .setInterpolator(new AccelerateInterpolator())
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        ViewUtils.setVisible(view, visibleNow, View.INVISIBLE);
                        view.setAlpha(1);
                        view.setScaleX(1);
                    }
                });
    } else {
        ViewUtils.setVisible(view, visibleNow, View.INVISIBLE);
    }
}
 
Example 11
Source File: VPAnim2Activity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public void transformPage(View view, float position) {
    int pageWidth = view.getMeasuredWidth();
    int pageHeight = view.getMeasuredHeight();

    Log.e("TAG", view + " , " + position + "");


    if (position < -1) { // [-Infinity,-1)
        // This page is way off-screen to the left.
        view.setScaleX(MIN_SCALE);
        view.setScaleY(MIN_SCALE);
        view.setPivotX(pageWidth);

    } else if (position <= 1) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
    { // [-1,1]

        float scaleFactor;

        if (position < 0) {
            scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 + position);

        } else {
            scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - position);
        }


        // Scale the page down (between MIN_SCALE and 1)
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);
        view.setPivotX(pageWidth * CENTER * (1 - position));


    } else { // (1,+Infinity]
        // This page is way off-screen to the right.
        view.setPivotX(0);
        view.setScaleX(MIN_SCALE);
        view.setScaleY(MIN_SCALE);
    }
}
 
Example 12
Source File: AddWalletView.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 13
Source File: FloatingView.java    From dingo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 拡大・縮小を行います。
 *
 * @param newScale 設定する拡大率
 */
private void setScale(float newScale) {
    // INFO:childにscaleを設定しないと拡大率が変わらない現象に対処するための修正
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View targetView = getChildAt(i);
            targetView.setScaleX(newScale);
            targetView.setScaleY(newScale);
        }
    } else {
        setScaleX(newScale);
        setScaleY(newScale);
    }
}
 
Example 14
Source File: MainActivity.java    From AndroidFloatLabel with Apache License 2.0 5 votes vote down vote up
@Override
public void onHideLabel(View label) {
    final float shift = label.getWidth() / 2;
    label.setScaleX(SCALE_X_SHOWN);
    label.setScaleY(SCALE_Y_SHOWN);
    label.setX(0f);
    label.animate().alpha(0).scaleX(SCALE_X_HIDDEN).scaleY(SCALE_Y_HIDDEN).x(shift);
}
 
Example 15
Source File: Overview.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void screenScrolled(View v, float progress) {
    float scale =1.0f - 0.1f * mScaleInterpolator
            .getInterpolation(Math.min(0.3f, Math.abs(progress)) / 0.3f);

    v.setPivotX(progress < 0 ? 0 : v.getMeasuredWidth());
    v.setPivotY(v.getMeasuredHeight() * 0.5f);
    v.setScaleX(scale);
    v.setScaleY(scale);
    v.setAlpha(scale);
}
 
Example 16
Source File: DepthPageTransformer.java    From Banner with Apache License 2.0 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
    if (position <= 0f) {
        view.setTranslationX(0f);
        view.setScaleX(1f);
        view.setScaleY(1f);
    } else if (position <= 1f) {
        final float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
        view.setAlpha(1 - position);
        view.setPivotY(0.5f * view.getHeight());
        view.setTranslationX(view.getWidth() * -position);
        view.setScaleX(scaleFactor);
        view.setScaleY(scaleFactor);
    }
}
 
Example 17
Source File: ZoomPageTransformer.java    From XBanner with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRightPage(View view, float position) {
    float scale = Math.max(mMinScale, 1 - position);
    float vertMargin = view.getHeight() * (1 - scale) / 2;
    float horzMargin = view.getWidth() * (1 - scale) / 2;
    view.setTranslationX( -horzMargin + vertMargin / 2);
    view.setScaleX( scale);
    view.setScaleY( scale);
    view.setAlpha( mMinAlpha + (scale - mMinScale) / (1 - mMinScale) * (1 - mMinAlpha));
}
 
Example 18
Source File: ZoomOutPageTransformer.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
@SuppressLint("NewApi")
public void transformPage(View view, float position)
{
    int pageWidth = view.getMeasuredWidth();
    int pageHeight = view.getMeasuredHeight();

    Log.e("TAG", view + " , " + position + "");

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

    } else if (position <= 1) //a页滑动至b页 ; a页从 0.0 -1 ;b页从1 ~ 0.0
    { // [-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(1);
    }
}
 
Example 19
Source File: a.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
static void g(View view, float f1)
{
    view.setScaleX(f1);
}
 
Example 20
Source File: AccordionTransformer.java    From BannerPager with Apache License 2.0 4 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
    view.setPivotX(position < 0 ? 0 : view.getWidth());
    view.setScaleX(position < 0 ? 1f + position : 1f - position);
}