在android中放大动画

在android中放大动画,android,android-animation,Android,Android Animation,我想在android中实现以下动画,我已经尝试过场景,但场景与文本不兼容,根据文档确认: 如果试图用动画调整TextView的大小,则在对象完全调整大小之前,文本将弹出到新位置。为避免此问题,请不要对包含文本的视图进行动画调整 请提供任何解决方案,放大的布局文本也可以包含图像。 这东西是如何工作的,但动画有点不稳定,我想布局高度最终值是先达到的,布局宽度稍后,必须解决这个问题。这是我的放大/缩小动画: public class EnlargeAnimation extends Animation

我想在android中实现以下动画,我已经尝试过场景,但场景与文本不兼容,根据文档确认:

如果试图用动画调整TextView的大小,则在对象完全调整大小之前,文本将弹出到新位置。为避免此问题,请不要对包含文本的视图进行动画调整

请提供任何解决方案,放大的布局文本也可以包含图像。

这东西是如何工作的,但动画有点不稳定,我想布局高度最终值是先达到的,布局宽度稍后,必须解决这个问题。这是我的放大/缩小动画:

public class EnlargeAnimation extends Animation {

private final int diffHeight;
private final int diffWidth;
private final int initialHeight;
private final int initialWidth;
private final View targetView;

public EnlargeAnimation(View targetView, float targetHeight, float targetWidth) {
    this.targetView = targetView;
    this.initialHeight = targetView.getMeasuredHeight();
    this.initialWidth = targetView.getMeasuredWidth();
    this.diffHeight = (int) (targetHeight-initialHeight);
    this.diffWidth = (int) (targetWidth-initialWidth);
}

@Override
public boolean willChangeBounds() {
    return true;
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {

    float newHeight = initialHeight + diffHeight * interpolatedTime;
    float newWidth = initialWidth + diffWidth * interpolatedTime;
    targetView.getLayoutParams().height = (int) newHeight;
    targetView.getLayoutParams().width = (int) newWidth;
    targetView.requestLayout();
}
}

此时将调用放大动画:

我正在使用viewpager,因此我必须将填充设置为负数以放大卡的大小:

  ValueAnimator paddingAnimator = ValueAnimator.ofInt(20, -10).setDuration(400);
                paddingAnimator.setInterpolator(new LinearInterpolator());
                paddingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int padding = (int) animation.getAnimatedValue();
                        view.setPadding(padding,
                                (int) DeviceUtils.convertDpToPx(50, v.getContext()), padding,
                                (int) DeviceUtils.convertDpToPx(50, v.getContext()));
                        view.requestLayout();
                    }
                });
                viewPagerItemSizeListener.onEnlarged();
                EnlargeAnimation
                        enlargeAnimation =
                        new EnlargeAnimation(cardView, screenHeight, screenWidth);
                enlargeAnimation.setDuration(400);
                enlargeAnimation.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        paddingAnimator.start();
                        seeExampleText.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        stage.setVisibility(View.GONE);
                        cardEnlargedWidth = cardView.getLayoutParams().width;
                        cardEnlargedHeight = cardView.getLayoutParams().height;
                        crossContianer.setVisibility(View.VISIBLE);
                        detailTextContianer.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                view.startAnimation(enlargeAnimation);

我想没有人在读它,但是如果变量有问题,让我知道我会编辑答案。

这东西是如何工作的,但是动画有点紧张,我想布局高度最终值是先达到的,布局宽度稍后,必须解决这个问题。这是我的放大/缩小动画:

public class EnlargeAnimation extends Animation {

private final int diffHeight;
private final int diffWidth;
private final int initialHeight;
private final int initialWidth;
private final View targetView;

public EnlargeAnimation(View targetView, float targetHeight, float targetWidth) {
    this.targetView = targetView;
    this.initialHeight = targetView.getMeasuredHeight();
    this.initialWidth = targetView.getMeasuredWidth();
    this.diffHeight = (int) (targetHeight-initialHeight);
    this.diffWidth = (int) (targetWidth-initialWidth);
}

@Override
public boolean willChangeBounds() {
    return true;
}

@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {

    float newHeight = initialHeight + diffHeight * interpolatedTime;
    float newWidth = initialWidth + diffWidth * interpolatedTime;
    targetView.getLayoutParams().height = (int) newHeight;
    targetView.getLayoutParams().width = (int) newWidth;
    targetView.requestLayout();
}
}

此时将调用放大动画:

我正在使用viewpager,因此我必须将填充设置为负数以放大卡的大小:

  ValueAnimator paddingAnimator = ValueAnimator.ofInt(20, -10).setDuration(400);
                paddingAnimator.setInterpolator(new LinearInterpolator());
                paddingAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int padding = (int) animation.getAnimatedValue();
                        view.setPadding(padding,
                                (int) DeviceUtils.convertDpToPx(50, v.getContext()), padding,
                                (int) DeviceUtils.convertDpToPx(50, v.getContext()));
                        view.requestLayout();
                    }
                });
                viewPagerItemSizeListener.onEnlarged();
                EnlargeAnimation
                        enlargeAnimation =
                        new EnlargeAnimation(cardView, screenHeight, screenWidth);
                enlargeAnimation.setDuration(400);
                enlargeAnimation.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        paddingAnimator.start();
                        seeExampleText.setVisibility(View.INVISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        stage.setVisibility(View.GONE);
                        cardEnlargedWidth = cardView.getLayoutParams().width;
                        cardEnlargedHeight = cardView.getLayoutParams().height;
                        crossContianer.setVisibility(View.VISIBLE);
                        detailTextContianer.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                view.startAnimation(enlargeAnimation);
我想没有人在读它,但是如果变量有什么让我困惑的地方,让我知道我会编辑答案