使用XML转换流畅的动画浮动 [英] Smooth floating animation using translation in XML

查看:233
本文介绍了使用XML转换流畅的动画浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发Android Eclipse的一个游戏,我试图让图像顺利转化上下看起来像它的上下浮动无限。由于是,它转换顺利,但在过渡看起来波涛汹涌不会降为上升,反之亦然。我不相信我有fromDelta和toDelta如何尽可能为工作单位牢牢把握。我试图寻找这个网站和谷歌有关信息,但同时能够找到解决我的所有其他问题,这样一来,是不是能够找到一个解决方案。

I'm developing a game for Android in Eclipse and I'm trying to get an image to smoothly translate up and down to look like it's floating up and down infinitely. As is, it translates smoothly, but looks choppy in the transition from going down to going up and vice versa. I don't believe I have a firm grasp on how fromDelta and toDelta work as far as units. I've tried searching this site and google for information on this, but, while able to find solutions to all my other issues this way, was not able to find a solution for this.

我的code为XML动画文件是如下:

My code for the XML animation file is below:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillEnabled="true"
android:fillAfter="true" >

<alpha android:fromAlpha="0.0" android:toAlpha="1.0" 
      android:interpolator="@android:anim/accelerate_interpolator" 
      android:duration="1000"
      android:fillAfter="true"/>

<translate
android:interpolator="@android:anim/linear_interpolator"
android:fromYDelta="0%p"
android:toYDelta="10%p"
android:duration="2000"
android:startOffset="0"
android:repeatCount="infinite"></translate>

<translate
android:interpolator="@android:anim/linear_interpolator"
android:fromYDelta="10%p"
android:toYDelta="-10%p"
android:duration="2000"
android:startOffset="2000"
android:repeatCount="infinite"></translate>

</set>

我试过从10%P做的0%P在第二个翻译,但没有奏效。从10%P也没有到0%第任何帮助将大大AP preciated。谢谢!

I've tried doing from 10%p to 0%p in the second translate but that didn't work. Neither did from 10%p to 0%p. Any help would be greatly appreciated. Thanks!

推荐答案

固定它!对于那些有兴趣,我终于找到了我的问题修复。我不得不设定重复模式,扭转和使用只是一个翻译运动。该解决方案是如下:

Fixed it! For those interested, I finally found a fix for my problem. I had to set the repeat mode to reverse and use just the one translate movement. The solution is below:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillEnabled="true"
android:fillAfter="true" >

<alpha android:fromAlpha="0.0" android:toAlpha="1.0" 
  android:interpolator="@android:anim/accelerate_interpolator" 
  android:duration="1000"
  android:fillAfter="true"/>

<translate
android:interpolator="@android:anim/linear_interpolator"
android:fromYDelta="0%p"
android:toYDelta="10%p"
android:duration="2000"
android:startOffset="0"
android:repeatCount="infinite"
android:repeatMode="reverse"></translate>

这篇关于使用XML转换流畅的动画浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆