overridePendingTransition在TabActivity里失效的解决办法

最近改版一个应用商店性质的应用,把UI界面改成TabHost+Viewpager组合,在最后一个Tab里要向其他的界面(Activity)跳转,发现跳转时原本正常的动画失效了,baidu了一下,有人说:设置-->显示-->允许所有动画,但是我手机的设置里面没有这个选项,况且之前是正常的,所以感觉问题不是出在这里,转投Google,终于在StackOverFlow上找到了答案。

I found out that the problem was because my view was a sub-activity inside a tab.
To correctly override the transitions I've overridden the onPause method on the TabActivity and it now works as expected.

翻译过来的意思大概是:

我发现这个问题是因为我的View是一个Tab里面的子Activity。我在继承了TabActivity的子类Activity中重写OnPause方法后,动画正常

附上代码片段:

[java]  view plain copy
  1. //没动画的代码  
  2. @Override  
  3. public void onClick(View v) {  
  4.     switch (v.getId()) {  
  5.     case R.id.rlUpdate:  
  6.         Intent intent = new Intent(v.getContext(), NeedUpdateActivity.class);  
  7.         startActivity(intent);  
  8.         overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);  
  9.         break;  
  10.     case .....  
  11.     }  
  12. }  
  13. //正常动画的代码  
  14. public class MainActivity extends TabActivity {  
  15.     .....  
  16.     @Override  
  17.     protected void onPause() {  
  18.         super.onPause();  
  19.         overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);  
  20.     }  
  21. }  
  22. @Override  
  23. public void onClick(View v) {  
  24.     switch (v.getId()) {  
  25.     case R.id.rlUpdate:  
  26.     Intent intent = new Intent(v.getContext(), NeedUpdateActivity.class);  
  27.     startActivity(intent);  
  28.     //overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);  
  29.     break;  
  30.     }  
  31. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值