您的位置:首页 > 其它

TabHost,标签页的使用

2016-06-24 12:18 316 查看
转载于: http://blog.csdn.net/shulianghan/article/details/18233209
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@android:id/tabhost"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<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"
android:orientation="horizontal"/>

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">

<RelativeLayout
android:id="@+id/tab01"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:gravity="center"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="text01"/>
</RelativeLayout>

<RelativeLayout
android:id="@+id/tab02"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:gravity="center"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="text02"/>
</RelativeLayout>

<RelativeLayout
android:id="@+id/tab03"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:gravity="center"
android:textSize="23sp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="text03"/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>
<span style="font-size:18px;">
</span>
<pre name="code" class="java"><span style="font-size:18px;">import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;

public class MainActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TabHost tabhost = getTabHost();
TabHost.TabSpec page1 = tabhost.newTabSpec("tab1").setIndicator("第一页").setContent(R.id.tab01);
tabhost.addTab(page1);

TabHost.TabSpec page2 = tabhost.newTabSpec("tab2").setIndicator("第二页").setContent(R.id.tab02);
tabhost.addTab(page2);

TabHost.TabSpec page3 = tabhost.newTabSpec("tab3").setIndicator("第三页").setContent(R.id.tab03);
tabhost.addTab(page3);
}
}
</span>




a13f
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: