简体   繁体   English

Android:在ViewAnimator的输入和输出动画之间添加延迟

[英]Android: Add delay between the in and out animation of ViewAnimator

I'm simply trying to animate my view transaction using a ViewAnimator. 我只是尝试使用ViewAnimator为我的视图事务设置动画。

But I want my view to slide out and in from the SAME side. 但我希望我的观点从同一侧滑出。

Since the in and out animation happen at the same time, how can I add a delay between the in and out animation so my in transaction appear nicely? 由于进出动画同时发生,如何在进出动画之间添加延迟,以便我的交易显得很好?

Just use this in ur animation xml : 只需在你的动画xml中使用它:

android:startOffset = "x"

It means that your animation will start after x milliseconds 这意味着您的动画将在x毫秒后开始

Your solution is perfect but can by complicated if using a ViewAnimator, after doing some test and more research, I finally found a VERY simple way. 你的解决方案是完美的,但如果使用ViewAnimator可能会很复杂,经过一些测试和更多研究后,我终于找到了一种非常简单的方法。 I ended up by adding android:startOffset in the XML animation. 我最后在XML动画中添加了android:startOffset。 This way the animation wait the desired amount of time before starting. 这样,动画在开始之前等待所需的时间量。

Exemple: 例:

If the slide out duration is set to 500ms, then set the startOffset of the slide in to 500ms. 如果滑出持续时间设置为500毫秒,则将幻灯片的startOffset设置为500毫秒。

Slide_in_from_bottom.xml Slide_in_from_bottom.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="100%" android:toYDelta="0%"
        android:duration="500" android:startOffset="[Replace with fade out duration]" />
</set>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM