转载请标明出处:http://blog.csdn.net/jjsyjiao/article/details/40980909
由于TabHost已经逐渐过时,现在开发已经不建议使用,将由Fragment代替,本文主要讲述Fragment替换TabHost的方法,代码简单易懂,适合初学者使用。
上个效果图先:
首先:
1、建个资源文件activity_main.xml;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="60dip"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<RelativeLayout
android:id="@+id/fotune"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/bottom_background_onclick_color" >
<ImageView
android:id="@+id/fotune_img"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_centerInParent="true"
android:background="@drawable/fotune_a" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/message"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/bottom_background_unclick_color" >
<ImageView
android:id="@+id/message_img"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_centerInParent="true"
android:background="@drawable/message_ia" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/account"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/bottom_background_unclick_color" >
<ImageView
android:id="@+id/account_img"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_centerInParent="true"
android:bac