I tried implementing FragmentTabHost it works but i want to animate when i click the tabs.
Here's a snippet of my tab host:
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);
These here are the animations that i am using:
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;
}
Sadly when i test this on my phone which is 4.4.4. There is no animation between tabs.