wen742538485 发表于 2013-1-30 04:15:00

Android TabHost使用、动态加载内容

使用TabHost有两种办法
1.在layout的xml文件里定义,格式如下:
Ruby代码
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@android:id/tabhost"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   
   <LinearLayout   
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <TabWidget
         android:id="@android:id/tabs"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"/>
      <FrameLayout
         android:id="@android:id/tabcontent"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
      </FrameLayout>   
    </LinearLayout>
</TabHost>

其中TabHost、TabWidget、FrameLayout的id必须如上,否则运行出错,甚至不能通过编译。
在代码中用
Java代码
TabHost myTabHost = (TabHost) findViewById(R.id.tabhost);   
TabWidget tabWidget = myTabHost.getTabWidget();   
myTabHost.addTab(tabHost.newTabSpec("tab1")   
                .setIndicator("tab1", getResources().getDrawable(R.drawable.mumule))   
                .setContent(R.id.view1));   

使用Tab.
2.继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。
使用方法与上面类型。
页: [1]
查看完整版本: Android TabHost使用、动态加载内容