Android 从左到右滑动动画 [英] Android Left to Right slide animation

查看:38
本文介绍了Android 从左到右滑动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个启动模式为单实例的活动.
使用 onfling(),我左右摆动它们.

I have three activities whose launch modes are single instance.
Using onfling(), I swing them left and right.

问题是当我从右向左滑动时,幻灯片过渡没问题,但是当我从左向右滑动时,我得到了从右向左滑动的过渡.

The problem is when I swipe right to left the slide transition is okay but when I swipe left to right, I get the transition of swiping right to left.

我知道为什么会发生这种情况,因为我总是在发送新的意图.但是,现在我需要更改从左向右滑动的动画.

I know why this is happening its because I am always sending new intents. But, now I need to change the animation of sliding left to right.

我知道有一个名为 overridingTransitionPending() 的方法,但我不知道如何在 XML 中定义我的动画.

I know there is a method named overridingTransitionPending(), but I do not know how to define my animation in XML.

推荐答案

res/anim/

这是从左到右的动画:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate android:fromXDelta="-100%" android:toXDelta="0%"
             android:fromYDelta="0%" android:toYDelta="0%"
             android:duration="700"/>
</set>

这是从右到左的动画:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="false">
  <translate
     android:fromXDelta="0%" android:toXDelta="100%"
     android:fromYDelta="0%" android:toYDelta="0%"
     android:duration="700" />
</set>

在你的编码中使用像从左到右这样的意图:

In your coding use intent like for left to right:

this.overridePendingTransition(R.anim.animation_enter,
                   R.anim.animation_leave);

在你的编码中使用像从右到左这样的意图

In your coding use intent like for right to left

this.overridePendingTransition(R.anim.animation_leave,
                               R.anim.animation_enter);

这篇关于Android 从左到右滑动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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