Android的TabHost組件-android的學習之旅(四十)

來源:互聯網
上載者:User

標籤:android

TabHost簡介

雖然,官方建議用Fagment取代TabHost,但是我們還是大概的介紹一下。TabHost是一種非常簡單的組件,TabHost可以很方便的在視窗放置多個標籤頁,每一個標籤頁相當於獲得了一個擺放位置。

注意

TabHost的內部需要兩個組件一個是TabWidget和FrameLayout兩個組件。

通話記錄介面
<?xml version="1.0" encoding="utf-8"?><TabHost xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"android:layout_height="match_parent"    android:layout_weight="1"    android:id="@android:id/tabhost"    >    <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:orientation="vertical">        <TabWidget            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:id="@android:id/tabs"/>        <FrameLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:id="@android:id/tabcontent">            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:orientation="vertical"                android:id="@+id/tab01">                <TextView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="hello"/>                <TextView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="hello"/>                </LinearLayout>            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:orientation="vertical"                android:id="@+id/tab02">                <TextView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="hello"/>                <TextView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="hello"/>            </LinearLayout>            <LinearLayout                android:layout_width="fill_parent"                android:layout_height="fill_parent"                android:orientation="vertical"                android:id="@+id/tab03">                <TextView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="hello"/>                <TextView                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:text="hello"/>            </LinearLayout>            </FrameLayout>        </LinearLayout></TabHost>
package peng.liu.test;import android.app.TabActivity;import android.os.Bundle;import android.widget.TabHost;public class MainActivity extends TabActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TabHost tabHost = getTabHost();        TabHost.TabSpec tabSpec = tabHost.newTabSpec("tab01").setIndicator("已接電話").setContent(R.id.tab01);        tabHost.addTab(tabSpec);        TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("tab02").setIndicator("呼叫電話").setContent(R.id.tab02);        TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("tab03").setIndicator("未接電話").setContent(R.id.tab03);        tabHost.addTab(tabSpec1);        tabHost.addTab(tabSpec2);    }}

Android的TabHost組件-android的學習之旅(四十)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.