2015-06-29 63 views
0

我试图添加动画时,选项卡更改,我有一个列表视图作为我的选项卡,现在我有动画工作。使用这种TabHost动画与更改选项卡

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; 
} 
基于以下后

Android - TabActivity with Transition animation

但随着我的名单来看,我有它一个头,和我想要的头留下来,只是列表更改,我怎么能改变这个?

回答

0

您只需拨打findViewById()方法getTabHost().getCurrentView()链,找到您的ListView并为其设置动画效果。

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

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