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.
推荐答案
您可以通过在 ViewFlipper
上设置 ScaleAnimations
来实现.我在没有第二个规模的情况下做了类似的事情.我有两个动画,一个是出去的视图,一个是进来的视图.我会把它们贴在这里作为你的起点.
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
,如下所示:
Then in the app I set them to the ViewFlipper
like this:
mViewFlipper.setInAnimation(context, R.anim.grow_from_middle);
mViewFlipper.setOutAnimation(context, R.anim.shrink_to_middle);
就像我说的,这与您所描述的不完全一样,但它非常接近并且可以帮助您入门.
Like I said, this is not exactly what you described, but it's pretty close and will get you started.
--编辑--
这是使用 pivotX 和 pivotY 的代码(好吧,在我的例子中只是 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屋!