活动之间的卡翻转动画 [英] Card Flip Animation between Activities

查看:109
本文介绍了活动之间的卡翻转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一href="http://developer.android.com/training/animation/cardflip.html">http://developer.android.com/training/animation/cardflip.html

静态布局之间的上面的链接开关。我想做一个 CardFlip 2之间有活动提前一个动态layout..Thanks ..:)

The above link Switches Between Static Layouts.. I want to do a CardFlip Between 2 Activities having a dynamic layout..Thanks in Advance..:)

我有两个活动...

  1. A Main_Activity 包含产品的详细信息(说的Galaxy S3)
  2. A Search_Activity ,查询该用户的搜索请求。
  1. A Main_Activity that Contains Details of a product(Say Galaxy s3)
  2. A Search_Activity that queries the users search request..

有一个在 Main_Activity 搜索按钮。当您单击按钮 Main_Activity 视图必须卡翻盖 Search_Activity 。同样当用户选择一个产品它应该卡片翻转副诗句。

There is a search button in the Main_Activity. When you click the button the Main_Activity view must card flip to Search_Activity. Similarly Once the user selects a product it should Card-Flip vice-verse.

我试图执行所提到的,在上面的网址..但它仅使用 XML 定义的两个静态布局之间翻转。而我实施搜索的动作条

I tried to implement as mentioned as in the Above URL.. But It only flips between two static layouts defined using XML. And I am implementing Search in the ActionBar

推荐答案

据我得到了你不能做完全活动之间的同一张卡翻转。

正如你可能已经知道你需要 overridePendingTransition(),以动画的活动之间的过渡(<一href="http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition%28int,%20int%29">doc这里)。 现在,所有你需要的是一个动画的资源做的伎俩。 我使用了这些:
fade_in.xml

From what I've got you can't do exactly that same card flip between activities.
BUT,
as you might already know you need overridePendingTransition() in order to animate transition between activities (doc here). Now all you need is an animation resource to do the trick. I used these:
fade_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
    android:duration="200"
    android:fromXScale="0.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="200"
    android:toXScale="1.0"
    android:toYScale="1.0" />

<alpha
    android:duration="1"
    android:fromAlpha="0.0"
    android:startOffset="200"
    android:toAlpha="1.0" />
</set>

fade_out.xml

fade_out.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
    android:duration="200"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.0"
    android:toYScale="1.0" />

<alpha
    android:duration="1"
    android:fromAlpha="1.0"
    android:startOffset="200"
    android:toAlpha="0.0" />
</set>

请注意,旋转动画旋转大约只有Z轴(一进入画面)在给定的支点位置(X,Y坐标),所以你不能用它来翻转绕Y轴旋转。
我所做的就是规模围在中间的宽度,同时保持它创建活动开启它的边幻想的高度。此外,进入和离开的活动淡入和淡出分别在宽度为0,所以它看起来像他们交换。的比例动画翻转的时间属性必须是相同的,因为所有的这两个动画startOffset 属性。
并不完美,但确实的伎俩我。
希望它能帮助。

Notice that the rotate animation rotates only around the Z-axis (the one going into the screen) at a given pivot position (x, y coordinates) so you can't use it to flip around the Y-axis.
What I've done is to scale the width around the middle while keeping the height which creates the illusion of the activity turning on it's side. Also, the entering and the exiting activities fade in and out respectively when the width is 0 so it looks like they are switching. The duration attribute of the scale of the flip in animation must be the same as all the startOffset attribute of both animations.
Not perfect but did the trick for me.
Hope it helps.

这篇关于活动之间的卡翻转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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