添加动画更换标签时, [英] Add animation when changing tabs
本文介绍了添加动画更换标签时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好 我有两个孩子的活动TabHost活动。什么是添加一个左 - 右的最佳解决方案?动画的子活动
Hello I have a TabHost activity with two child activities. What would be the best solution to add a "left - right" animation for the child activities?
祝商祺!
推荐答案
喜
这样做的最好的解决办法是添加动画布局
假设你有两个标签
Hi
The best solution for this is to add animation to layouts
suppose you have two tabs
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
then on the 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;
}
希望这将有助于你得到一些想法
Hope this will help you to get some idea
这篇关于添加动画更换标签时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文