Android中如何实现选项卡功能
导读:本文共2816.5字符,通常情况下阅读需要9分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 首先创建Android工程命名自己的Activity为HelloTabWidget在main.xml或者自己定义的*.xml文件中创建一个TabHost,需要两个元素TabWidget和FrameLayout 通常会把这两个元素放到LinearLayout中。FrameLayout作为改变内容content用的。注意:TabWidget和FrameLayout ... ...
目录
(为您整理了一些要点),点击可以直达。- (5):< LinearLayout
- (9):< TabWidget
- (13):< FrameLayout
- (17):< TextView
- (22):< TextView
- (27):< TextView
- (32):< /FrameLayout>
- (33):< /LinearLayout>
- (34):< /TabHost>
- (41):< LinearLayout
- (45):< TabWidget
- (49):< FrameLayout
- (53):< TextView
- (58):< TextView
- (63):< TextView
- (68):< /FrameLayout>
- (69):< /LinearLayout>
- (70):< /TabHost>
< ?xmlversion="1.0"encoding="utf-8"?>
< TabHostxmlns: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">
< TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="thisisatab"/>
< TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="thisisanothertab"/>
< TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="thisisathirdtab"/>
< /FrameLayout>
< /LinearLayout>
< /TabHost>
< ?xmlversion="1.0"encoding="utf-8"?>
< TabHostxmlns: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">
< TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="thisisatab"/>
< TextView
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="thisisanothertab"/>
< TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="thisisathirdtab"/>
< /FrameLayout>
< /LinearLayout>
< /TabHost>
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost=getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").
setIndicator("TAB1").setContent(R.id.textview1));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").
setIndicator("TAB2").setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").
setIndicator("TAB3").setContent(R.id.textview3));
mTabHost.setCurrentTab(0);
}
Android中如何实现选项卡功能的详细内容,希望对您有所帮助,信息来源于网络。