安卓学习第31课——TabHost

虽然这个组件已经不推荐使用了,但是我还是学习了一下。他的xml有点复杂。

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/tabcontent">
           <LinearLayout
               android:id="@+id/tab01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tv1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="努尔哈赤" />
        </LinearLayout>
          <LinearLayout
              android:id="@+id/tab02"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tv2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="努尔哈赤" />
        </LinearLayout>
          <LinearLayout
              android:id="@+id/tab03"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/tv3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="努尔哈赤" />
        </LinearLayout>
        </FrameLayout>
    </LinearLayout>

</TabHost>

我认为它整体用的是TabHost,然后在标签部分用的是TabWidget,页面部分用的是FrameLayout。里面每个标签内容用LinearLayout包裹

package com.example.tabhost;

import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TabHost tabHost=getTabHost();
        TabSpec tab1=tabHost.newTabSpec("tab1").setIndicator("已接电话").setContent(R.id.tab01);
        tabHost.addTab(tab1);
        TabSpec tab2=tabHost.newTabSpec("tab2").setIndicator("呼出电话",
                getResources().getDrawable(R.drawable.ic_launcher)).setContent(R.id.tab02);
        tabHost.addTab(tab2);

        TabSpec tab3=tabHost.newTabSpec("tab3").setIndicator("未接电话").setContent(R.id.tab03);

        tabHost.addTab(tab3);

    }
}
时间: 2024-07-28 21:17:31

安卓学习第31课——TabHost的相关文章

安卓学习第13课——BaseAdapter

BaseAdapter创建这么一个对象,需要些四个方法. int getCount(); Object getItem(int position); long getItemId(int position);View getView(int position, View convertView, ViewGroup parent);(1)列表中的项数(2)返回值的列表内容(3)获得postion处的列表项的ID(4)该列表项里的组件 package com.example.baseadapter

安卓学习第12课——SimpleAdapter

SimpleAdapter一点也不简单,他的参数就带了5个,天哪,晕了.. 今天学的这个适配器, public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) 看这个大概明白,参数分别是第一个:表示访问整个android应用程序接口,基本上所有的组件都需要,一般都写this(改天研究一下),第二个应该是这个List对象

安卓学习第9课——计时器chronometer

今天学习了钟表及计时器.. 我觉得AnalogClock和DigitalClock直接使用就可以.唯一需要知道的就是AnalogClock是可以修改表盘和分针时针的. 方法是android:dail及android:hand_minute和hand_hour. 下面介绍的是计时器的用法. 首先xml中只要放入一个chronometer和一个按钮即可.为的是是点击启动按钮,开始计时,20s停止. package com.example.chronometer; import android.app

安卓学习第11课——AutoCompleteTextView

...在百度上搜了这么一段.理解了ArrayAdapter的三个参数的用途 1. 这个小例子是要显示一个数组,我们就用ArrayAdapter,数组适配器,数据的数据类型<>是String类型的,数据的数据类型还可以是其他的包括对象类型的 2. ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(ArrayListDemo.this, android.R.layout.simple_list_item

安卓学习第10课——listview

1.普通listview <LinearLayout 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" androi

安卓学习第8课——开关ToggleButton、Switch

今天学的是对开关的监听,两种开关ToggleButton和switch <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="ma

安卓学习第三课——常见布局

1.相对布局 简单的说,就是通过描述每个组件所在的位置,使用的layout_below等,就是控制组件与组件之间的位置关系. 2.绝对布局 就是通过描述他的x,y坐标来确定位置 3.线性布局 有两种是水平和竖直对其方式,一般情况下整体会使用线性布局,来排列众多的组件 3.帧布局 我感觉就是一层一层的,默认的情况下,多个组件是在同一个位置,所以你需要去修改位置.同时可以选择是否显示. 这可以用来描述视频播放器暂停键的控制方法. 代码如下. <?xml version="1.0" e

安卓学习第7课——checkbutton

1.布局 <TableLayout 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:orienta

安卓学习第6课——button

今天学会了按钮的背景图片是可以改变的... 背景可以不是图片,而是一个xml文件. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="带文字的图片按钮" android:background="@drawable/button_selector" android:textSize=&