android.view.View#setScaleX ( )源码实例Demo

下面列出了android.view.View#setScaleX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
/**
 * 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);
	}
}
 
@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));
	}
}
 
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);
}
 
源代码5 项目: XBanner   文件: ZoomPageTransformer.java
@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));
}
 
源代码6 项目: Banner   文件: DepthPageTransformer.java
@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);
    }
}
 
源代码7 项目: Trebuchet   文件: Overview.java
@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);
}
 
源代码8 项目: AndroidFloatLabel   文件: MainActivity.java
@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);
}
 
源代码9 项目: dingo   文件: FloatingView.java
/**
 * 拡大・縮小を行います。
 *
 * @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);
    }
}
 
源代码10 项目: ETHWallet   文件: AddWalletView.java
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);
    }
}
 
源代码11 项目: AndroidAnimationExercise   文件: VPAnim2Activity.java
@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);
    }
}
 
源代码12 项目: AcDisplay   文件: AcDisplayFragment.java
/**
 * 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);
    }
}
 
源代码13 项目: iBeebo   文件: ZoomOutPageTransformer.java
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);
    }
}
 
源代码14 项目: FragmentMaster   文件: EnterOvershootAnimator.java
@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);
}
 
源代码15 项目: newsApp   文件: DepthPageTransformer.java
@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);
}
 
@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);
}
 
@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);
}
 
@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);
    }
}
 
源代码19 项目: MiBandDecompiled   文件: a.java
static void g(View view, float f1)
{
    view.setScaleX(f1);
}
 
源代码20 项目: BannerPager   文件: AccordionTransformer.java
@Override
protected void onTransform(View view, float position) {
    view.setPivotX(position < 0 ? 0 : view.getWidth());
    view.setScaleX(position < 0 ? 1f + position : 1f - position);
}
 
 方法所在类
 同类方法