设为首页 加入收藏

TOP

Android 选项卡(TabHost)例子(一)
2014-11-24 11:10:56 来源: 作者: 【 】 浏览:0
Tags:Android 选项 TabHost 例子

程序主要代码如下:


1、布局文件tab.xml,在布局文件中需要注意的是:如果TabHost标签中引用TabWidget标签,则必须设置其android:id="@android:id/tabs",而FrameLayout标签的id必须设置为:android:id="@android:id/tabcontent",否则会出现空指针异常。


< xml version="1.0" encoding="utf-8" >
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="fill_parent"
android:layout_height="fill_parent">

android:id="@android:id/tabs"
android:layout_alignParentBottom="true" //这


条语句的作用是把TabWidget设置到屏幕的下方,默认在屏幕上方。
android:layout_width="fill_parent"
android:layout_height="wrap_content">


android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/tab1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="20dip">


android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:layout_gravity="center"
android:src="@drawable/home"/>

android:id="@+id/tab2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="20dip">


android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:layout_gravity="center"


android:src="@drawable/garbage"/>

android:id="@+id/tab3"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="20dip">


android:layout_width="wrap_content"


android:layout_height="wrap_content"

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇编译Linux 2.6.8.1版本内核并从新.. 下一篇Android原理揭秘系列之VacantCell..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·【C语言】动态内存管 (2025-12-27 06:23:20)
·C语言中的内存管理 - (2025-12-27 06:23:16)
·C语言指南:C语言内 (2025-12-27 06:23:14)
·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)