Android的动画 - 翻转 [英] Android Animation - Flip
问题描述
我需要创建一个动画 - 翻转的视图,并显示另一个
I need to create an animation - Flip a view and show another one.
目前所示视图的宽度被缓慢下降到零,之后的宽度的视图将要示出的,必须从零增大。
The width of currently shown view is decreased slowly to zero and after that the width of the view-to-be-shown must be increased from zero.
在此期间,该高度变为从当前显示高度稍微降低的高度,然后再返回。
During this time, the height goes from the currently-shown-height to slightly-decreased-height and back again.
我怎样才能做到这一点...使用ViewFlipper。
How can I achieve this... using a ViewFlipper.
推荐答案
您可以做到这一点与 ScaleAnimations
一组 ViewFlipper
。我做了类似的事情,没有第二个刻度。我有两个动画,一个是观点走出去,一个用于视图进来。我会张贴在这里为出发点,为你。
You can do that with ScaleAnimations
set on a ViewFlipper
. I do a similar thing without the second scale. I have two animations, one for the view going out and one for the view coming in. I'll post them here as a starting point for you.
shrink_to_middle.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:fillAfter="false"
android:duration="200" />
<translate
android:fromYDelta="0"
android:toYDelta="50%"
android:duration="200"/>
</set>
grow_from_middle.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:fillAfter="false"
android:startOffset="200"
android:duration="200" />
<translate
android:fromYDelta="50%"
android:toYDelta="0"
android:startOffset="200"
android:duration="200"/>
</set>
然后在应用程序,我将它们设置为 ViewFlipper
是这样的:
mViewFlipper.setInAnimation(context, R.anim.grow_from_middle);
mViewFlipper.setOutAnimation(context, R.anim.shrink_to_middle);
就像我说的,这不正是你所描述的,但它是pretty的接近,将会让你开始。
Like I said, this is not exactly what you described, but it's pretty close and will get you started.
- 编辑 -
下面是一个使用pivotX和pivotY的code(当然,只是pivotY在我的情况):
Here is the code using the pivotX and pivotY (well, just pivotY in my case):
shrink_to_middle.xml
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotY="50%"
android:fillAfter="false"
android:duration="200" />
grow_from_middle.xml
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotY="50%"
android:fillAfter="false"
android:startOffset="200"
android:duration="200" />
这篇关于Android的动画 - 翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!