易采站长站为您分析Android编程之TabWidget选项卡用法,结合实例形式较为详细的分析了TabWidget选项卡的具体实现技巧与使用注意事项,需要的朋友可以参考下
本文实例讲述了Android编程之TabWidget选项卡用法。,具体如下:
1 概览
TabWidget与TabHost。tab组件一般包括TabHost和TabWidget、FrameLayout,且TabWidget、FrameLayout属于TabHost。
是否继承TabActivity的问题
实现步骤。两种实现方式,一种是将每个Tab的布局嵌在TabHost中的FrameLayout中,每个Tab的内容布局与显示都在FrameLayout中进行,缺点是布局会显得很臃肿;一种是每个Tab从FrameLayout中独立出来,以Activity呈现,这样使得每个Tab有单独的布局。
2 效果图
Widget在顶部的情形:
3 主要布局
3.1 TabMain布局
方式一:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://www.easck.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_alignParentBottom="true"
android:background="#424242" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/theme"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/theme_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab1" />
</LinearLayout>
<LinearLayout
android:id="@+id/wallpaper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/wallpaper_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab2" />
</LinearLayout>
<LinearLayout
android:id="@+id/iconbg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/iconbg_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab3" />
</LinearLayout>
<LinearLayout
android:id="@+id/screenlock"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/screenlock_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab4" />
</LinearLayout>
<LinearLayout
android:id="@+id/effect"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/effect_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab5" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>
</TabHost>














