【问题标题】:Scale Animation Causes View to shorten before start of animation缩放动画导致视图在动画开始之前缩短
【发布时间】:2014-10-28 19:37:30
【问题描述】:

所以我有这个缩放动画,它应该做的是将视图缩放到全高的 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);

有什么想法吗?感谢阅读。

【问题讨论】:

  • 使用 ONE 比例动画和自定义插值器,在域 0..pi 中的作用类似于 /\ 或 sin() 函数

标签: android animation scale


【解决方案1】:

取决于 cmets 中的@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>

【讨论】:

  • 哦,这更有意义。谢谢。
  • @MohamedZaatari 这不是应该使用的方式,您应该使用插值器来使其工作,例如尝试 CycleInterpolator
  • @pskink 插值器用于控制缩放的加速,而不是控制你可以阅读Here关于插值器属性的位置
  • @MohamedZaatari " 这允许加速、减速、重复等基本动画效果(alpha、缩放、平移、旋转)。" OP 问题就是这种情况:动画重复一次并反转,只需使用 CycleInterpolator 来实现,而不是像 1/0.7 之类的魔法东西
  • @pskink 你是对的,我会用你的有用信息更新我的答案......谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-30
  • 2014-04-20
  • 1970-01-01
  • 1970-01-01
  • 2014-06-12
  • 1970-01-01
相关资源
最近更新 更多