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

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

问题描述

我正在尝试向我的 TabActivty 添加动画.例如,当用户选择第二个选项卡时,我希望新活动来自右侧.当用户选择第一个选项卡时,我希望活动来自左侧.

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

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

我该怎么做?

谢谢.

问候.

V.

推荐答案

这可以正常工作:

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

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