android初學---widget之tab

1、佈局

<?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/tabview1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/tabviewtext1" />

    <TextView
        android:id="@+id/tabview2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/tabviewtext2" />

    <TextView
        android:id="@+id/tabview3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/tabviewtext3" />

</FrameLayout>

2、代碼實現

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;

public class TabDemoActivity extends TabActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  TabHost tabHost = this.getTabHost();
  LayoutInflater.from(this).inflate(R.layout.tablayout,
    tabHost.getTabContentView(), true);
  tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1")
    .setContent(R.id.tabview1));
  tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2")
    .setContent(R.id.tabview2));
  tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3")
    .setContent(R.id.tabview3));
 }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章