I am new to Android and in my project I have requirement
i.e I have six tabs but I show only three tabs on screen and for rest of tabs I use ScrollView.Here selected tab item must be in the middle,first when I enter into screen I show middle item is active(i.e selected).
That's fine but how could I set this middle item as middle when I scroll for remaining Tabs?
can anybody give suggestion for getting solution.
Check this out :)
public void centerTabItem(int position) {
tabHost.setCurrentTab(position);
final TabWidget tabWidget = tabHost.getTabWidget();
final int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
final int leftX = tabWidget.getChildAt(position).getLeft();
int newX = 0;
newX = leftX + (tabWidget.getChildAt(position).getWidth() / 2) - (screenWidth / 2);
if (newX < 0) {
newX = 0;
}
horizontalScrollView.scrollTo(newX, 0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With