我在 Android 中创建了一个简单的选项卡项目
MainActivity.java
public class MainActivity extends TabActivity {
// TabSpec Names
private static final String TAB1 = "Tab1";
private static final String TAB2 = "Tab2";
private static final String TAB3 = "Tab3";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Inbox Tab
TabSpec inboxSpec = tabHost.newTabSpec(TAB1);
Intent inboxIntent = new Intent(this, Tab1.class);
inboxSpec.setIndicator(TAB1);
// Tab Content
inboxSpec.setContent(inboxIntent);
// Outbox Tab
TabSpec PriceSpec = tabHost.newTabSpec(TAB2);
Intent PriceIntent = new Intent(this, Tab2.class);
PriceSpec .setIndicator(TAB2);
PriceSpec.setContent(PriceIntent);
// Profile Tab
TabSpec DistanceSpec = tabHost.newTabSpec(TAB3);
Intent DistanceIntent = new Intent(this, Tab3.class);
DistanceSpec .setIndicator(TAB3);
DistanceSpec.setContent(DistanceIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(inboxSpec);
tabHost.addTab(PriceSpec);
tabHost.addTab(DistanceSpec);
//Set the current value tab to default first tab
tabHost.setCurrentTab(0);
//Setting custom height for the tabs
final int height = 45;
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;
}
}
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
输出::
How can i make a horizontal set of 5 buttons on top of the tab to get something like this in the below figure
我需要进行哪些代码更改main.xml
?