Увеличить анимацию в андроиде - PullRequest
1 голос
/ 07 мая 2019

Я хочу добиться приведенной ниже анимации в Android. Я пробовал сцены, но сцены не работают с текстом, что подтверждается документами:

"Если вы попытаетесь изменить размер TextView с анимацией, текст будет перемещен в новое место до полного изменения размера объекта. Чтобы избежать этой проблемы, не анимируйте изменение размера представлений, содержащих текст."

Пожалуйста, любое решение, увеличенный текст макета также может содержать изображения. анимационное видео

1 Ответ

0 голосов
/ 20 мая 2019

эта штука сработала как-то, но анимация немного нервная, я думаю, что окончательное значение высоты макета сначала достигается, а позже layoutWidth, нужно это исправить. это моя анимация увеличения / уменьшения:

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);

Я думаю, что никто не читает это, но если что-то не так с переменными, дайте мне знать, что я отредактирую ответ.

...