查看相对于原始动画的比例值
View animation scale values relative to original
我想在 TextView 上制作一个基本动画,当用户点击它时会缩小,然后缩小到原始大小以提供视觉反馈。阅读文档,似乎有多种方法可以为 Android 上的属性设置动画,但我决定使用视图动画,定义如下 XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true" android:interpolator="@android:anim/accelerate_interpolator">
<scale
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"/>
<scale
android:startOffset="100"
android:fromXScale="1.0"
android:toXScale="2.0"
android:fromYScale="1.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"/>
这很好用,但令我感到奇怪的是,我必须计算我需要多少来缩放第二个标签,而不是只能使用相对于原始标签的值。有没有办法在第二个标签中使用相对于原始元素的值(即使用 fromXscale="0.5" 和 toXscale="1.0")?
如果我答对了你的问题,试试这个
tv.animate().scaleXBy(2.0f).scaleYBy(2.0f).setDuration(100).setInterpolator(new LinearInterpolator()).start();
您可以添加反向重复策略或只添加缩减动画。
我想在 TextView 上制作一个基本动画,当用户点击它时会缩小,然后缩小到原始大小以提供视觉反馈。阅读文档,似乎有多种方法可以为 Android 上的属性设置动画,但我决定使用视图动画,定义如下 XML:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true" android:interpolator="@android:anim/accelerate_interpolator">
<scale
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="100"/>
<scale
android:startOffset="100"
android:fromXScale="1.0"
android:toXScale="2.0"
android:fromYScale="1.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="50"/>
这很好用,但令我感到奇怪的是,我必须计算我需要多少来缩放第二个标签,而不是只能使用相对于原始标签的值。有没有办法在第二个标签中使用相对于原始元素的值(即使用 fromXscale="0.5" 和 toXscale="1.0")?
如果我答对了你的问题,试试这个
tv.animate().scaleXBy(2.0f).scaleYBy(2.0f).setDuration(100).setInterpolator(new LinearInterpolator()).start();
您可以添加反向重复策略或只添加缩减动画。