【问题标题】:Android: scale animation does not work when direction is changedAndroid:改变方向时缩放动画不起作用
【发布时间】:2013-02-06 07:26:09
【问题描述】:

在我的 Android 应用中,我有一个缩放动画。

<set xmlns:android="http://schemas.android.com/apk/res/android"   android:interpolator="@android:anim/accelerate_interpolator"   android:fillEnabled="true"  android:fillAfter="true"  >
 <scale android:fromXScale="1.0" android:toXScale="0.0"   android:fromYScale="1.0"    android:toYScale="1.0"      android:duration="32000"   />
 </set>

它工作正常。它从左到右缩放视图。但我需要从右到左缩放。所以当我修改fromXScale="-1.0" 时,动画不会发生,视图会立即缩放而没有动画。 我的反向动画xml如下:

 <set xmlns:android="http://schemas.android.com/apk/res/android"   android:interpolator="@android:anim/accelerate_interpolator"   android:fillEnabled="true"  android:fillAfter="true"  >            
  <scale android:fromXScale="-1.0" android:toXScale="0.0"   android:fromYScale="1.0"    android:toYScale="1.0"      android:duration="32000"   /> 
 </set>

如何从相反方向为视图设置动画?我的代码有什么问题?

【问题讨论】:

    标签: android xml scale android-animation


    【解决方案1】:

    您还应该在动画中添加android:fillBefore="true"

    在前向动画中,您的视图通常具有 1 的比例,这意味着您不需要在开始时设置它。但是在反向动画中,您从默认(即 1)开始并动画到... 1

    【讨论】:

      【解决方案2】:

      使用 Pivot 解决了这个问题。通过 pivotX 和 pivotY 控制动画的方向是一种更好的做法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-05
        • 2019-01-10
        • 1970-01-01
        相关资源
        最近更新 更多