您的位置:首页 > 其它

FragmentTabHost

2016-06-21 17:57 225 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: