下面列出了android.view.View#getScaleY ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void scaleTo(@NonNull View aView, float scaleX, float scaleY, long duration, long delay, final Runnable aCallback) {
if (aView.getScaleX() == scaleX && aView.getScaleY() == scaleY) {
if (aCallback != null) {
aView.post(aCallback);
}
return;
}
aView.animate().setStartDelay(delay).scaleX(scaleX).scaleY(scaleX).setDuration(duration).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (aCallback != null) {
aView.post(aCallback);
}
}
}).setUpdateListener(animation -> aView.invalidate());
}
Transforms(View view) {
mTranslationX = view.getTranslationX();
mTranslationY = view.getTranslationY();
mTranslationZ = ViewCompat.getTranslationZ(view);
mScaleX = view.getScaleX();
mScaleY = view.getScaleY();
mRotationX = view.getRotationX();
mRotationY = view.getRotationY();
mRotationZ = view.getRotation();
}
private float getValue(int propertyConstant) {
final View node = mView;
switch (propertyConstant) {
case ViewPropertyAnimatorConstant.TRANSLATION_X:
return node.getTranslationX();
case ViewPropertyAnimatorConstant.TRANSLATION_Y:
return node.getTranslationY();
case ViewPropertyAnimatorConstant.TRANSLATION_Z:
return node.getTranslationZ();
case ViewPropertyAnimatorConstant.ROTATION:
return node.getRotation();
case ViewPropertyAnimatorConstant.ROTATION_X:
return node.getRotationX();
case ViewPropertyAnimatorConstant.ROTATION_Y:
return node.getRotationY();
case ViewPropertyAnimatorConstant.SCALE_X:
return node.getScaleX();
case ViewPropertyAnimatorConstant.SCALE_Y:
return node.getScaleY();
case ViewPropertyAnimatorConstant.X:
return mView.getLeft() + node.getTranslationX();
case ViewPropertyAnimatorConstant.Y:
return mView.getTop() + node.getTranslationY();
case ViewPropertyAnimatorConstant.Z:
return node.getElevation() + node.getTranslationZ();
case ViewPropertyAnimatorConstant.ALPHA:
return mView.getAlpha();
}
return 0;
}
@Nullable
private Animator createAnimation(@NonNull final View view, float startScale, float endScale, @Nullable TransitionValues values) {
final float initialScaleX = view.getScaleX();
final float initialScaleY = view.getScaleY();
float startScaleX = initialScaleX * startScale;
float endScaleX = initialScaleX * endScale;
float startScaleY = initialScaleY * startScale;
float endScaleY = initialScaleY * endScale;
if (values != null) {
Float savedScaleX = (Float) values.values.get(PROPNAME_SCALE_X);
Float savedScaleY = (Float) values.values.get(PROPNAME_SCALE_Y);
// if saved value is not equal initial value it means that previous
// transition was interrupted and in the onTransitionEnd
// we've applied endScale. we should apply proper value to
// continue animation from the interrupted state
if (savedScaleX != null && savedScaleX != initialScaleX) {
startScaleX = savedScaleX;
}
if (savedScaleY != null && savedScaleY != initialScaleY) {
startScaleY = savedScaleY;
}
}
view.setScaleX(startScaleX);
view.setScaleY(startScaleY);
Animator animator = TransitionUtils.mergeAnimators(
ObjectAnimator.ofFloat(view, View.SCALE_X, startScaleX, endScaleX),
ObjectAnimator.ofFloat(view, View.SCALE_Y, startScaleY, endScaleY));
addListener(new TransitionListenerAdapter() {
@Override
public void onTransitionEnd(@NonNull Transition transition) {
view.setScaleX(initialScaleX);
view.setScaleY(initialScaleY);
transition.removeListener(this);
}
});
return animator;
}
public Transforms(View view) {
translationX = view.getTranslationX();
translationY = view.getTranslationY();
translationZ = view.getTranslationZ();
scaleX = view.getScaleX();
scaleY = view.getScaleY();
rotationX = view.getRotationX();
rotationY = view.getRotationY();
rotationZ = view.getRotation();
}
public void updateView(View v) {
if (v != null) {
this.alpha = v.getAlpha();
this.x = v.getX();
this.y = v.getY();
this.z = atLeastLollipop ? v.getZ() : 0;
this.width = v.getWidth();
this.height = v.getHeight();
this.expansionScaleX = v.getScaleX();
this.expansionScaleY = v.getScaleY();
this.dispositionAngle = v.getRotation();
this.dispositionAngleX = v.getRotationX();
this.dispositionAngleY = v.getRotationY();
}
}
public static boolean isChildInCenterY(RecyclerView recyclerView, View view) {
int childCount = recyclerView.getChildCount();
int[] rvLocationOnScreen = new int[2];
int[] vLocationOnScreen = new int[2];
recyclerView.getLocationOnScreen(rvLocationOnScreen);
int middleY = (int) (rvLocationOnScreen[1] + recyclerView.getHeight() * recyclerView.getScaleY() / 2);
if (childCount > 0) {
view.getLocationOnScreen(vLocationOnScreen);
if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() * view.getScaleY() >= middleY) {
return true;
}
}
return false;
}
@Override
public float get(Object mountContent) {
final View asView = assertIsView(mountContent, this);
final float scale = asView.getScaleX();
if (scale != asView.getScaleY()) {
throw new RuntimeException(
"Tried to get scale of view, but scaleX and scaleY are different");
}
return scale;
}
private static void unsetScale(View view, NodeInfo nodeInfo) {
if (nodeInfo.isScaleSet()) {
if (view.getScaleX() != 1) {
view.setScaleX(1);
}
if (view.getScaleY() != 1) {
view.setScaleY(1);
}
}
}
@Override
public void viewToRect(View v, Rect outRect) {
outRect.left = 0;
outRect.top = 0;
computeLocationRelativeToContainer(v, outRect);
// If a view is scaled, its position will also shift accordingly. For optimization, only
// consider this for the last node.
outRect.left += (1 - v.getScaleX()) * v.getWidth() / 2;
outRect.top += (1 - v.getScaleY()) * v.getHeight() / 2;
outRect.right = outRect.left + (int) (v.getScaleX() * v.getWidth());
outRect.bottom = outRect.top + (int) (v.getScaleY() * v.getHeight());
}
/**
* 焦点缩放动画
*
* @param oldOrNewFocusView
* @param
*/
protected void runFocusScaleAnimation(@Nullable View oldOrNewFocusView, float scaleX, float scaleY)
{
if (null == oldOrNewFocusView)
return;
if (scaleX != oldOrNewFocusView.getScaleX() || scaleY != oldOrNewFocusView.getScaleY())
{
oldOrNewFocusView.animate().scaleX(scaleX).scaleY(scaleY).setDuration(mAnimDuration).start();
}
}
@Override
public float getValue(View view) {
return view.getScaleY();
}
@Override
public float getValue(View view) {
return view.getScaleY();
}
@Override
public Float get(View object) {
return object.getScaleY();
}
public static boolean isViewHiddenByScale(View v) {
return v.getScaleX() == 0 && v.getScaleY() == 0;
}
static float getScaleY(View view) {
return view.getScaleY();
}
static float getScaleY(View view) {
return view.getScaleY();
}
public static float getScaleY(View view) {
return view.getScaleY();
}
static float getScaleY(View view) {
return view.getScaleY();
}
private void cacheData(View view) {
mPageScaleX = view.getScaleX();
mPageScaleY = view.getScaleY();
mScaleX = getScaleX();
mScaleY = getScaleY();
}