Android的 - TabActivity与过渡动画 [英] Android - TabActivity with Transition animation

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

问题描述

我想要的动画添加到我的TabActivty。例如,当用户选择第二选项卡,我希望新的活动来自右边。当用户选择了第一个选项卡,我想活动来自于左侧。

我已经找到了如何添加一个动画,但我想再次添加一个。这里是code我使用:

 动漫公共inFromRightAnimation()
{
    动画inFromRight =新TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,+ 1.0F,
            Animation.RELATIVE_TO_PARENT,0.0,
            Animation.RELATIVE_TO_PARENT,0.0,
            Animation.RELATIVE_TO_PARENT,0.0);
    inFromRight.setDuration(240);
    inFromRight.setInterpolator(新AccelerateInterpolator());
    返回inFromRight;
}
 

  getTabHost()。setOnTabChangedListener(新OnTabChangeListener(){
       公共无效onTabChanged(字符串tabId)
       {
           查看currentView = getTabHost()getCurrentView()。
           currentView.setAnimation(inFromRightAnimation());
       }
});
 

我怎么能这样做?

感谢。

问候。

解决方案

这正常工作:

  getTabHost()。setOnTabChangedListener(新OnTabChangeListener(){
     公共无效onTabChanged(字符串tabId)
     {
            查看currentView = getTabHost()getCurrentView()。
            如果(getTabHost()getCurrentTab()> currentTab)
            {
                currentView.setAnimation(inFromRightAnimation());
            }
            其他
            {
                currentView.setAnimation(outToRightAnimation());
            }

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

和动画:

 动漫公共inFromRightAnimation()
{
    动画inFromRight =新TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,+ 1.0F,
            Animation.RELATIVE_TO_PARENT,0.0,
            Animation.RELATIVE_TO_PARENT,0.0,
            Animation.RELATIVE_TO_PARENT,0.0);
    inFromRight.setDuration(240);
    inFromRight.setInterpolator(新AccelerateInterpolator());
    返回inFromRight;
}

动漫公共outToRightAnimation()
{
    动画outtoLeft =新TranslateAnimation(
            Animation.RELATIVE_TO_PARENT,-1.0F,
            Animation.RELATIVE_TO_PARENT,0.0,
            Animation.RELATIVE_TO_PARENT,0.0,
            Animation.RELATIVE_TO_PARENT,0.0);
    outtoLeft.setDuration(240);
    outtoLeft.setInterpolator(新AccelerateInterpolator());
    返回outtoLeft;
}
 

I'm trying to add an animation to my TabActivty. For example, when the user select the 2nd tab, I want the new activity comes from the right. When the user select the first tab, I want the activity comes from the left.

I've found how to add one animation, but I want to add one again. Here is the code I'm using:

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;
}

And

getTabHost().setOnTabChangedListener(new OnTabChangeListener() {
       public void onTabChanged(String tabId)
       {
           View currentView = getTabHost().getCurrentView();
           currentView.setAnimation( inFromRightAnimation() );
       }
});

How can I do that?

Thanks.

Regards.

V.

解决方案

This works correctly:

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();
     }
});

And the animations:

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与过渡动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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