标签:android tab tabhost tabactivity
Tab标签页是UI设计时经常使用的UI控件,可以实现多个分页之间的快速切换,每个分页可以显示不同的内容。<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/view1"
android:background="@drawable/blue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="这里是Tab1里的内容。"/>
<TextView android:id="@+id/view2"
android:background="@drawable/red"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="这里是Tab2"/>
<TextView android:id="@+id/view3"
android:background="@drawable/green"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Tab3"/>
</FrameLayout>package com.rainsong.tabdemo;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
public class MainActivity extends TabActivity
{
TabHost mTabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mTabHost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.tab,
mTabHost.getTabContentView(), true);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab1")
.setContent(R.id.view1));
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab2")
.setContent(R.id.view2));
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab3")
.setContent(R.id.view3));
}
}
Class Overview
Container for a tabbed window view. This object holds two children: a set of tab labels that the user clicks to select a specific tab, and a FrameLayout object that displays the contents of that page.
Specify the id of the view that should be used as the content of the tab.
Android UI之Tab(TabActivity+TabHost实现)
标签:android tab tabhost tabactivity
原文地址:http://blog.csdn.net/hantangsongming/article/details/41603859