gpt4 book ai didi

android - 更改选项卡时添加动画

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:05 26 4
gpt4 key购买 nike

你好我有一个包含两个子 Activity 的 TabHost Activity 。为子 Activity 添加“左 - 右”动画的最佳解决方案是什么?

最好的问候!

最佳答案

你好
最好的解决方案是在布局中添加动画
假设你有两个标签

tabs = (TabHost) this.findViewById(R.id.tabhost_id);
tabs.setup();
tspec1 = tabs.newTabSpec(name_of_1st_tab)
tspec1.setIndicator(....);
tspec1.setContent(R.id.tab_1_layout_id);
tab1Layout = (LinearLayout)findViewById(R.id.tab_1_layout_id);

tspec2 = tabs.newTabSpec(name_of_2nd_tab)
tspec2.setIndicator(....);
tspec2.setContent(R.id.tab_1_layout_id);
tab1Layout = (LinearLayout)findViewByIdR.id.tab_2_layout_id);

然后在 TabChangedListener 上

    tabs.setOnTabChangedListener(new OnTabChangeListener() {

public void onTabChanged(String tabId) {
tab1Layout.setAnimation(outToLeftAnimation());
tab2Layout.setAnimation(inFromRightAnimation());
}
});

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(ConstandsUsed.ANIMATIION_DURATION);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}

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

希望这对你有所帮助

关于android - 更改选项卡时添加动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4077440/

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