Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用imageview的某些给定时间间隔反转缩放动画_Android_Animation_Android Animation_Zooming - Fatal编程技术网

Android 使用imageview的某些给定时间间隔反转缩放动画

Android 使用imageview的某些给定时间间隔反转缩放动画,android,animation,android-animation,zooming,Android,Animation,Android Animation,Zooming,在反转动画之前,我想反转放大动画,但要有一定的时间延迟。下面是无限反转的代码,但在反转动画之前,我需要设置一些时间间隔 zoom_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" > <scale xmlns:android="http://

在反转动画之前,我想反转放大动画,但要有一定的时间延迟。下面是无限反转的代码,但在反转动画之前,我需要设置一些时间间隔

zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:repeatMode="reverse"
    android:duration="5000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="2"
    android:toYScale="2" >
</scale>

您可以像这样添加延迟

long delayTimeInMilliseconds = 1000;

Handler handler = new Handler();

handler.postDelayed(new Runnable()
{
    @Override
    public void run()
    {
        // here you can start your reverse animation
    }
}, delayTimeInMilliseconds);

最后,下面zoomout.xml中的更改帮助解决了这个问题

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="5000"
        android:fromXScale="2"
        android:fromYScale="2"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1" >
    </scale>

</set>

有一种更干净、更好的解决方案。不要将动画拆分为两个不同的xml文件并使用动画侦听器,而是尝试将它们合并为一个文件zoom.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="2"
    android:toYScale="2" />
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000"
    android:startOffset="5500"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5" />
</set>

完成了

谢谢你的回复,奥马尔,我可以这样做,但我找不到任何方法来保存和播放反向动画。您可以在_reverse.xml中为反向动画创建另一个zoom_,并通过添加延迟在动画中开始zoom_。我也这样做了,但图像视图将返回到正常位置,然后在_reverseanimation中开始zoom_。您可以显示代码吗。您是否也将fillAfter属性设置为true?在编辑时更新了我的代码。请查看。这将反转动画,而不是从zoomin completed(缩放完成)的位置。希望您理解问题的答案,我也会尝试这种方法,看看它是如何工作的检查更新的xml。有一个多余的重复模式,我没有注意到。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="5000"
        android:fromXScale="2"
        android:fromYScale="2"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1"
        android:toYScale="1" >
    </scale>

</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="2"
    android:toYScale="2" />
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000"
    android:startOffset="5500"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5" />
</set>
imageView= (ImageView) findViewById(R.id.imageView);
zoom = AnimationUtils.loadAnimation(this, R.anim.zoom);
imageView.setAnimation(zoom);