FragmentTabHost

来源:互联网 发布:快枪手炒股软件 编辑:程序博客网 时间:2024/06/11 20:46
xml布局文件:<?xml version="1.0" encoding="utf-8"?><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"    android:orientation="vertical">    <FrameLayout        android:id="@+id/realtabcontent"        android:layout_width="fill_parent"        android:layout_height="0dip"        android:layout_weight="1"/>    <android.support.v4.app.FragmentTabHost        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:id="@android:id/tabhost"         >        <FrameLayout              android:id="@android:id/tabcontent"            android:layout_width="0dp"            android:layout_height="0dp"            android:layout_weight="0"            />    </android.support.v4.app.FragmentTabHost></LinearLayout>

代码:

FragmentTabHost tabHost= (FragmentTabHost) findViewById(android.R.id.tabhost);//找到fragmentTabHost  tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);//setup  for (int i=0;i<list.length;i++) {      TabHost.TabSpec tabSpec =tabHost.newTabSpec("aa"+i+"bb").setIndicator(getview(i));      tabHost.addTab(tabSpec,list[i], null);//addtab   }//获得tab布局
public View getview(int i){    View view = layoutInflater.inflate(R.layout.home_item, null);    TextView textView = (TextView) view.findViewById(R.id.home_item_tv);    textView.setText("aa");    return view;}


0 0
原创粉丝点击