首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用旋转动画在视图之间过渡的ViewAnimator

问使用旋转动画在视图之间过渡的ViewAnimator
EN

Stack Overflow用户
提问于 2011-10-07 00:23:54
回答 2查看 3.5K关注 0票数 1

我想使用ViewAnimator从一个视图转换到另一个视图(在我的测试应用程序中,视图是TextViews)。下面列出了我的两个动画。我看到的行为是,当我触发模拟器时,动画就会立即开始,而不是让InAnimation运行,而且一旦它完成了,就会让OutAnimation运行。我看到的看起来像是一个风车--旋转出来的视图垂直于旋转进来的视图。我想看到视图从正常的水平位置(0度)旋转到垂直位置(90度);然后我想看到视图从垂直位置(-90度)旋转到水平位置(0度)。

@anim/rotate_out.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
    android:pivotY="50%" android:repeatCount="0" android:duration="500"
    android:interpolator="@android:anim/linear_interpolator">
</rotate>

@anim/rotate_in.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="-90" android:toDegrees="0" android:pivotX="50%"
    android:pivotY="50%" android:repeatCount="0" android:duration="500"
    android:interpolator="@android:anim/linear_interpolator">
</rotate>

在主要的活动onCreate中...

代码语言:javascript
复制
va = (ViewAnimator) findViewById(R.id.ViewFlipper01);
va.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_in));
va.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_out));

有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-07 00:35:16

也许?@anim/rotate_outin.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
  <rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:fromDegrees="0" android:toDegrees="90" android:pivotX="50%"
      android:pivotY="50%" android:repeatCount="0" android:duration="500"
      android:interpolator="@android:anim/linear_interpolator">
  </rotate>
</set>
票数 3
EN

Stack Overflow用户

发布于 2011-10-14 16:34:35

可以在here中找到ViewAnimator的源代码。根据那里的showOnly()方法,有意将两个动画并行启动,因此当一个视图“移出”时,另一个视图已经“移入”。因此,为了实现您的目标,您必须在动画中添加一些延迟,以便在输出动画已经完成时开始。您可以将输出动画设置为android:duration="500“,将android:startOffset="500”设置为动画内动画。只需确保两者的值相同即可。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7677422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档