缩放动画导致视图在开始动画之前缩短

时间:2014-10-27 20:31:25

标签: android animation scale

所以我有这个缩放动画,它应该做的是将视图缩放到整个高度的70%,然后将其缩放回原始大小。我有两个具有不同startOffsets的缩放动画。

我遇到的问题是在动画开始之前的视图比例。因此,当动画开始时,它们与已经缩短的缩放视图一起工作。

这是我的动画xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/linear_interpolator" >
    <scale
        android:duration="300"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:startOffset="200"
        android:toXScale="1.0"
        android:toYScale="0.7"
        />
    <scale
        android:duration="300"
        android:fillAfter="true"
        android:fromXScale="1.0"
        android:fromYScale="0.7"
        android:startOffset="1000"
        android:toXScale="1.0"
        android:toYScale="1.0"
        />
</set>

以下是我如何称呼这个动画:

mScaleTop = AnimationUtils.loadAnimation(this, R.anim.scale_top);
mTopView.startAnimation(mScaleTop);

有什么想法吗?谢谢你的阅读。

1 个答案:

答案 0 :(得分:4)

取决于评论中的@pskink通知

如果您的动画采用循环模式,则只能将android:interpolator属性设置为@android:anim/cycle_interpolator" 因此,您只能使用第一阶段,然后将返回原始状态...

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/cycle_interpolator" >

<scale
    android:duration="300"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:startOffset="200"
    android:toXScale="1.0"
    android:toYScale="0.7" />

</set>

否则如果您想使用linear_interpolator 您还必须从1.0而非0.7缩放高度,因为1.0表示当前状态

android:fromYScale="1.0"表示100%当前状态和= 70%的原始状态......

因此您必须将高度android:fromYScale="1.0"缩放为android:fromXScale="1.42"

因为:android:fromYScale="1.0" = 70%来自原始尺寸,你必须将70%的42%添加到相当于原始高度的100%....

 <?xml version="1.0" encoding="utf-8"?>
 <set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/linear_interpolator" >

<scale
    android:duration="300"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:startOffset="200"
    android:toXScale="1.0"
    android:toYScale="0.7"
    />
<scale
    android:duration="300"
    android:fillAfter="true"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:startOffset="1000"
    android:toXScale="1.0"
    android:toYScale="1.42"
    />
</set>