【问题标题】:fillAfter and fillEnabled not working in Android view animation XMLfillAfter 和 fillEnabled 在 Android 视图动画 XML 中不起作用
【发布时间】:2020-06-04 22:00:52
【问题描述】:

我很好奇这种行为......我目前正在动画 XML 中设置这两个值:

    android:fillEnabled="true"
    android:fillAfter="true"

但是,动画完成后转换不会应用......它总是重置。当我通过代码以编程方式设置它时,它似乎确实有效:

    animation.setFillEnabled(true);
    animation.setFillAfter(true);

所以我只是好奇这应该如何工作,因为我宁愿在 XML 上设置它。谢谢!

【问题讨论】:

  • 你的问题有我想要的答案
  • 作为 xml 顺序加载动画和启动导致这个问题与一个动画与 fillafter true 作品完美

标签: android animation


【解决方案1】:

我遇到了同样的问题,这对我有用:

<set
    android:fillEnabled="true"
    android:fillAfter="true"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:fromYDelta="0"
        android:toYDelta="-20%p"
        android:duration="7000" />

</set>

将属性fillEnabledfillAfter放入Set标签​​中。

【讨论】:

  • 我在使用 RotateAnimation 时遇到了这个问题,您的评论帮助解决了这个问题。干杯。
  • 非常感谢,帮我解决了这个问题 :) 将您链接到另一个帖子 :)
  • 不适用于我在 Nexus 4 和 4.4.4 上分别设置最小和目标集 14 和 19 的动画。动画总是恢复到原来的 ImageView。
  • 嗨@RichieHH 我面临同样的问题。你的问题有解决办法吗?
  • 作为 xml 顺序加载动画和启动导致这个问题与一个动画与 fillafter true 作品完美
【解决方案2】:

如果你没有设置标签并且只是在做翻译或类似的事情,它也可以工作。

<translate xmlns:android="http://schemas.android.com/apk/res/android"       
    android:interpolator="@android:anim/linear_interpolator"       
    android:fromXDelta="0"
    android:toXDelta="0"
    android:fromYDelta="1000"
    android:toYDelta="-300" 
    android:startOffset="100"
    android:duration="1000"
    android:fillAfter="true" />

【讨论】:

    【解决方案3】:

    一般情况下,在根元素上使用 fillAfterfillEnabled

    要么

    <?xml version="1.0" encoding="utf-8"?>
    <translate
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true"
        android:fillEnabled="true"
        android:fromXDelta="0%"
        android:toXDelta="-100%"
        android:duration="500" />
    

    <?xml version="1.0" encoding="utf-8"?>
    <set
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true"
        android:fillEnabled="true">
        <translate
            android:fromXDelta="0%"
            android:toXDelta="-100%"
            android:duration="500" />
    </set>
    

    【讨论】:

    • 实际上我并没有在根目录中设置这些值,而是在内部设置中,所以我遇到了这个问题。
    【解决方案4】:

    将 fillEnabled 和 fillAfter 属性放入 set 标记有助于解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多