3.9 TabSpec与TabHost

TabHost类官方文档地址:http://developer.android.com/reference/android/widget/TabHost.html

Android 实现tab视图有2种方法,一种是在布局页面中定义<tabhost>标签,另一种就是继承tabactivity.但是我比较喜欢第二种方式,应为如果页面比较复杂的话你的XML文件会写得比较庞大,用第二种方式XML页面相对要简洁得多。

【读书笔记《Android游戏编程之从零开始》】6.Android 游戏开发常用的系统控件(TabHost、ListView)

 

<?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:background="@drawable/mm1"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="第一个Tab" />

    <EditText
        android:id="@+id/et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="第二个Tab" />

    <LinearLayout
        android:id="@+id/myLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/mm2"
        android:orientation="vertical" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="第三个Tab" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="第三个Tab" />
    </LinearLayout>

</LinearLayout>
activity_main.xml

相关文章:

  • 2021-08-01
  • 2021-12-07
  • 2022-12-23
  • 2021-10-19
  • 2021-04-08
  • 2021-04-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
相关资源
相似解决方案