如何根据视图在屏幕上的位置制作android缩放动画并将该视图集中在中心?

Het*_*tal 1 scaling animation android zooming android-animation

我想要这样的动画:日历动画

我想在日历上缩放动画并将当前日期集中到中心。我是android动画的新手,我做了一些缩放的事情:

Zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
    android:duration="1000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="2"
    android:toYScale="2" />
</set>
Run Code Online (Sandbox Code Playgroud)

但使用它,它将日历缩放到中心,但我希望当前日期位于中心。有人知道如何制作整个动画吗?任何帮助,将不胜感激。

aiw*_*una 5

您需要获得想要位于中心的视图/内容的位置,因为您需要进行一些翻译

这里的示例缩放到 TextView 的中心,并在 ConstraintView 内随机位置

要放大到需要平移视图的特定位置,使该点位于中心,您可以通过更改 difX 和 difY 公式来完成

float layoutWitdh = layout.getWidth();
        float layoutHeight = layout.getHeight();

        float x = view.getX();
        float y = view.getY();
        float w = view.getWidth();
        float h = view.getHeight();

        float difX = (layoutWitdh - w) / 2 - x;
        float difY = (layoutHeight - h) / 2 - y;

        view.animate().translationX(difX).translationY(difY).scaleY(5).scaleX(5).setDuration(1000);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:

检查这个项目https://github.com/aiwiguna/AndroidZoom

在此输入图像描述