我尝试实现FragmentTabHost它可以工作但我想点击标签时动画。
以下是我的标签主持人的片段:
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
View currentView = mTabHost.getCurrentView();
if (mTabHost.getCurrentTab() > currentTab) {
currentView.setAnimation(inFromRightAnimation());
} else {
currentView.setAnimation(outToRightAnimation());
}
currentTab = mTabHost.getCurrentTab();
}
});
mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
mTabHost.addTab(
mTabHost.newTabSpec("Tab 1").setIndicator("Tab 1", null),
PostSoovyFragment.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("Tab 2").setIndicator("Tab 2", null),
SooviesFragment.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("Tab 3").setIndicator("Tab 3", null),
SettingsFragment.class, null);
这些是我正在使用的动画:
private 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;
}
private 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;
}
可悲的是,当我在4.4.4手机上测试时。标签之间没有动画。