我有一个ActivityGroup打算开发一个tabHost. 其中一个选项卡包含两个活动。问题是当我在这两个活动之间移动时,它们之间没有滑动。旧活动消失,新活动自动出现在屏幕上。
我需要实现的是 - 当我从活动 2 移回活动 1 时,活动 2 必须通过向右滑动离开屏幕,而新活动(活动 1)必须通过从左向右滑动进入屏幕.
当使用意图在活动之间移动时,效果类似于android默认样式!
到目前为止,我取得的成就是:
当我尝试从活动 2 移动到活动 1 时:活动 2(旧活动)从屏幕上消失,屏幕变黑,新活动通过从左向右滑动进入屏幕。如果我能设法让旧的活动也通过滑动离开屏幕,那就太好了。
这是我从旧活动返回到新活动的代码:
Animation animation = null;
Window oldWindow = manager.getCurrentActivity().getWindow();
if(oldWindow != null)
{
animation = AnimationUtils.loadAnimation(this, R.anim.right_to_left);
View v =oldWindow.getDecorView();
v.startAnimation(animation);
}
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index); index--;
String lastId = mIdList.get(index);
lastIntent = manager.getActivity(lastId).getIntent();
newView = manager.startActivity(lastId, lastIntent).getDecorView();
newView.startAnimation(AnimationUtils.loadAnimation(this, R.anim.left_to_right));
if(newView != null)
{
setContentView(newView);
}
One big bug is this: if I remove this line from my code: `setContentView(newView)` I get the desired effect for the old activity. Meaning the old activity leaves the screen by sliding, but the new one never comes in.
如果我把那条线放回去,旧的活动不会做任何滑动就会消失!!!!
我使用三星 Galaxy 进行测试,我尝试使用overridePendingTransition,但它对动画没有影响。
这是我的xml文件:
right_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3500" />
</set>
left_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3500"/>
</set>
谢谢你。希望您能够帮助我。