tabhost中activity跳转动画不显示的解决办法

【1】如果是tabhost中的activity跳到其他的activity,用这篇blog的方法即可

http://blog.sina.com.cn/s/blog_8db8914301010t31.html

public class AnimCommon {

public static int in = 0;
public static int out = 0;
public static void set(int a, int b){
in = a ;
out = b;
}
public static void clear(){
in = 0;
out = 0;
}
}
下面是tabactivity 类的onPause()
@Override
protected void onPause() {
System.out.println("pause");
if(AnimCommon.in!=0 && AnimCommon.out!=0){
super.overridePendingTransitio n(AnimCommon.in, AnimCommon.out);
AnimCommon.clear();
}
super.onPause();
}

下面是跳转时的代码:
Intent intent = new Intent(InformActivity.this, InformItemActivity.class);
AnimCommon.set(R.anim.zoom_enter,R.anim.zoom_exit); 
startActivity(intent);

这样就可以解决这个问题了。

【2】如果是tabhost里面的两个activity

那么用以下代码

getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
    public void onTabChanged(String tabId)
    {
           View currentView = getTabHost().getCurrentView();
           if (getTabHost().getCurrentTab() > currentTab)
           {
               currentView.setAnimation( inFromRightAnimation() );
           }
           else
           {
               currentView.setAnimation( outToRightAnimation() );
           }


           currentTab = getTabHost().getCurrentTab();
    }
});

 
public Animation inFromRightAnimation()
{
   Animation inFromRight = new TranslateAnimation(
           Animation.RELATIVE_TO_PARENT, +1.0f,
           Animation.RELATIVE_TO_PARENT, 0.0f,
           Animation.RELATIVE_TO_PARENT, 0.0f,
           Animation.RELATIVE_TO_PARENT, 0.0f);
   inFromRight.setDuration(240);
   inFromRight.setInterpolator(new AccelerateInterpolator());
   return inFromRight;
}


public Animation outToRightAnimation()
{
   Animation outtoLeft = new TranslateAnimation(
           Animation.RELATIVE_TO_PARENT, -1.0f,
           Animation.RELATIVE_TO_PARENT, 0.0f,
           Animation.RELATIVE_TO_PARENT, 0.0f,
           Animation.RELATIVE_TO_PARENT, 0.0f);
   outtoLeft.setDuration(240);
   outtoLeft.setInterpolator(new AccelerateInterpolator());
   return outtoLeft;
}

原文地址:https://www.cnblogs.com/aukle/p/3235241.html