Android 如何在TabWidget的每个选项卡中添加更多项目?
我已经使用TabHost和TabWidget编写了一个简单的tab程序,但我只能向每个选项卡添加一项。。我想添加文本视图、图像视图和按钮,但无法。。这是我的xml代码:Android 如何在TabWidget的每个选项卡中添加更多项目?,android,android-tabhost,android-tabs,Android,Android Tabhost,Android Tabs,我已经使用TabHost和TabWidget编写了一个简单的tab程序,但我只能向每个选项卡添加一项。。我想添加文本视图、图像视图和按钮,但无法。。这是我的xml代码: <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_paren
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+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="98dp" >
<TextView
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Tab1"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Tab2"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Tab3"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
</FrameLayout>
</LinearLayout>
</TabHost>
如何将图像视图与现有文本视图一起添加到选项卡1?您可以使用操作栏中的选项卡,如下所示:
private-ViewPager-mPager;
私人寻呼器;
私有静态最终int NUM_PAGES=3;
在onCreate()中
final ActionBar ActionBar=getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setNavigationMode(actionBar.NAVIGATION\u MODE\u选项卡);
mPager=(ViewPager)findViewById(R.id.pager);
mPagerAdapter=新屏幕幻灯片页面适配器(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setOnPageChangeListener(新的ViewPager.SimpleOnPageChangeListener(){
@凌驾
已选择页面上的公共无效(内部位置){
actionBar.setSelectedNavigationItem(位置);
}
});
ActionBar.TabListener TabListener=新建ActionBar.TabListener(){
@凌驾
已重新选择公共选项卡(选项卡,
android.app.FragmentTransaction(ft){
}
@凌驾
已选择的公共空栏(选项卡,
android.app.FragmentTransaction(ft){
setCurrentItem(tab.getPosition());
}
@凌驾
已选择“公用”选项卡(选项卡,
android.app.FragmentTransaction(ft){
}
};
对于(int i=0;i
以及您的主活动.xml: