gpt4 book ai didi

Android - 带有过渡动画的 TabActivity

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:02 25 4
gpt4 key购买 nike

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

我找到了如何添加一个动画,但我想再添加一个。这是我正在使用的代码:

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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10009155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com