标签(TabHost)
2015-07-31 23:25
190 查看
标签(TabHost):由于手机屏幕大小有限,为了更好地显示信息,我们可以设置多个标签,每当我们点击一个标签,就会显示这个标签中所设置的内容。这样做可以有效的
节省屏幕空间。
1、代码:(这个程序并没有用到main.xml布局文件,而是新创建了一个布局文件,所以在此不写main.xml文件的代码了)
节省屏幕空间。
1、代码:(这个程序并没有用到main.xml布局文件,而是新创建了一个布局文件,所以在此不写main.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:orientation="vertical" > <LinearLayout //设置一个线性垂直排列的线性布局 android:id="@+id/xian1" <span style="white-space:pre"> </span> //设置id,以便查找 android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/edit" android:layout_width="500px" android:layout_height="wrap_content" android:text="请输入你要找的车" /> <Button android:id="@+id/but1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" /> </LinearLayout> <LinearLayout <span style="white-space:pre"> </span>//设置一个线性垂直排列的线性布局 android:id="@+id/xian2"<span style="white-space:pre"> </span>//设置id,以便查找 android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/edit2" android:layout_width="500px" android:layout_height="wrap_content" android:text="请输入你要找的tt车" /> <Button android:id="@+id/but2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" /> </LinearLayout> <LinearLayout <span style="white-space:pre"> </span>//设置一个线性垂直排列的线性布局 android:id="@+id/xian3"<span style="white-space:pre"> </span>//设置id,以便查找 android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <EditText android:id="@+id/edit3" android:layout_width="500px" android:layout_height="wrap_content" android:text="请输入你要找的pao车" /> <Button android:id="@+id/but3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" /> </LinearLayout> </LinearLayout>MainActivity.java文件的内容。
package com.example.tabhost; import android.app.ActionBar.Tab; import android.app.Activity; import android.app.TabActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class MainActivity extends TabActivity { private TabHost T = null; private int[] resourse = new int[]{R.id.xian1,R.id.xian2,R.id.xian3};//内嵌布局文件的id @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.T = super.getTabHost();//取得TabHost对象 //寻找我们之前写好的t.xml文件,并实例化布局文件 LayoutInflater.from(this).inflate(R.layout.t, this.T.getTabContentView(),true);//true表示实例化布局文件中的组件 for (int i = 0; i < resourse.length; i++) { //创建一个选项卡 TabSpec TS = this.T.newTabSpec("kkkk" + i); //设置标签名称 TS.setIndicator("标签--" + (i+1)); //为选项卡的内容指定视图的ID TS.setContent(this.resourse[i]); //添加选项卡 this.T.addTab(TS); } } }本程序采取的方法是继承TabActivity类,但是TabActivity在android 4.0就已经过时了,已经被Fragment所替代了。
相关文章推荐
- 第三方微信授权登录的iOS代码分析
- nutch 学习 过滤器
- 在VM10上安装openfiler初探
- java中UDP传输协议
- [CareerCup] 4.3 Create Minimal Binary Search Tree 创建最小二叉搜索树
- Android 开发新特性
- hdoj 1050 Moving Tables【贪心区间覆盖】
- 【leetcode c++】111 Minimum Depth of Binary Tree
- Mysql之查询、where、常用函数、having
- 转:JRE与JDK的区别详解
- Mac下常用的操作
- Java--类
- Android BuildConfig使用
- 怀旧!Windows最后一款产品Windows 10面世,30年前的它是这样的…
- Spark的TaskScheduler和DagScheduler
- HLSL效果框架实例之高斯模糊
- SpringMVC:Name for argument type ERROR
- 把 Mac 上的 bash 换成 zsh
- 面试题37_两个链表的第一个公共结点
- leetcode:the skyline problem