Reputation: 888
I have these 4 tabs as below. The problem is whenever I increase the tabs the tab size gets smaller. Is there any solution when they can simply be scrolled horizontally and also have the same size.
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Maths
TabSpec mathspec = tabHost.newTabSpec("Maths");
mathspec.setIndicator("Maths");
Intent mathIntent = new Intent(this, MathActivity.class);
mathspec.setContent(mathIntent);
// Tab for Units
TabSpec unitsspec = tabHost.newTabSpec("Units");
// setting Title and Icon for the Tab
unitsspec.setIndicator("Units");
Intent unitsIntent = new Intent(this, UnitsActivity.class);
unitsspec.setContent(unitsIntent);
// Tab for Physics
TabSpec physicsspec = tabHost.newTabSpec("Physics");
// setting Title and Icon for the Tab
physicsspec.setIndicator("Physics");
Intent physicsIntent = new Intent(this, PhysicsActivity.class);
physicsspec.setContent(physicsIntent);
// Tab for Chemistry
TabSpec chemistryspec = tabHost.newTabSpec("Chemistry");
// setting Title and Icon for the Tab
chemistryspec.setIndicator("Chemistry");
Intent chemistryIntent = new Intent(this, ChemistryActivity.class);
chemistryspec.setContent(chemistryIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(mathspec); // Adding maths tab
tabHost.addTab(unitsspec); // Adding units tab
tabHost.addTab(physicsspec); // Adding physics tab
tabHost.addTab(chemistryspec); // Adding chemistry tab
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextSize(10);
}
}
}
Upvotes: 0
Views: 441
Reputation: 6899
Switch over to Fragments. You will never face such an issue.
See this tutorial.
Moreover tab activity gets deprecated.
Upvotes: 1