(一)

知识点:id使用系统自带

1.效果图:

2.布局

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--选项卡标题表-->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<!--选项卡布局-->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout> </TabHost>

也可以在  activity_main.xml布局中使用include

tab1.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tab01">
<TextView
android:text="LinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout>

tab2.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab02">
<TextView
android:text="RelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

tab3.xml

 <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab03">
<TextView
android:text="AbsoluteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</AbsoluteLayout>

2.MainActivity.java

 package com.example.administrator.hello2;

 import android.app.TabActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost; public class MainActivity extends TabActivity { private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); tabHost = getTabHost(); LayoutInflater.from(MainActivity.this).inflate(R.layout.tab1,tabHost.getTabContentView(),true);
LayoutInflater.from(MainActivity.this).inflate(R.layout.tab2,tabHost.getTabContentView(),true);
LayoutInflater.from(MainActivity.this).inflate(R.layout.tab3,tabHost.getTabContentView(),true); tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("线性布局").setContent(R.id.tab01));
tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("相对布局").setContent(R.id.tab02));
tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("绝对布局").setContent(R.id.tab03)); }
}

最新文章

  1. AngularJS的学习--TodoMVC的分析
  2. cocos2dx-3.x 导出自定义类到 lua 过程详解
  3. Nested Class Templates
  4. 打包静态库.a文件的方法(ar,ranlib,nm命令介绍)
  5. 【Python】回文
  6. Go语言-通道类型
  7. UNIX网络编程——epoll的 et,lt关注点
  8. 类Objects
  9. ubuntu“少折腾”
  10. mvc partialView+kendo window
  11. python学习笔记---文件的操作
  12. bash内置命令的特殊性,后台任务的&quot;本质&quot;
  13. ubuntu kylin18 安装NVIDIA驱动
  14. Daily record-September
  15. 《TCP/IP 详解 卷1:协议》第 3 章:链路层
  16. ActiveMQ broker解析
  17. Stay hungry, Stay foolish 的原义
  18. 网络请求 get 请求时, 如果参数中的字符带有+号
  19. Android 自定义注解(Annotation)
  20. 一些实用的adb命令

热门文章

  1. memcache client 的递增 incr 问题
  2. (转)Notepad++
  3. NET中IL理解(转)
  4. HDU2553 N皇后问题---(dfs)
  5. Tomcat部署时war和war exploded区别及验证
  6. 基于js的地理数据的几何运算turfjs
  7. 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
  8. JS组件入门
  9. MSP432P401R时钟入门
  10. 记一次CUDA编程任务