您的位置:首页 > 移动开发

App底部导航(Fragment与ActivityGroup)

2016-03-18 17:01 288 查看
Android的3.0版本加入Fragment。在API 13的时候Android就已经将ActivityGroup废弃掉了,并且官方推荐的替代方式就是使用Fragment,因为它使用起来更加的灵活。那么剩下的问题就是如何借助Fragment来完成类似于TabHost一般的效果了,因此我们自然要动起手来了。



》MainActivity.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

<FrameLayout

android:id="@+id/content"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1" >

</FrameLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="60dp"

android:background="@drawable/tab_bg" >

<RelativeLayout

android:id="@+id/message_layout"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:orientation="vertical" >

<ImageView

android:id="@+id/message_image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@drawable/message_unselected" />

<TextView

android:id="@+id/message_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:text="消息"

android:textColor="#82858b" />

</LinearLayout>

</RelativeLayout>

<RelativeLayout

android:id="@+id/contacts_layout"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:orientation="vertical" >

<ImageView

android:id="@+id/contacts_image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@drawable/contacts_unselected" />

<TextView

android:id="@+id/contacts_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:text="联系人"

android:textColor="#82858b" />

</LinearLayout>

</RelativeLayout>

<RelativeLayout

android:id="@+id/news_layout"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:orientation="vertical" >

<ImageView

android:id="@+id/news_image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@drawable/news_unselected" />

<TextView

android:id="@+id/news_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:text="动态"

android:textColor="#82858b" />

</LinearLayout>

</RelativeLayout>

<RelativeLayout

android:id="@+id/setting_layout"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" >

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:orientation="vertical" >

<ImageView

android:id="@+id/setting_image"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:src="@drawable/setting_unselected" />

<TextView

android:id="@+id/setting_text"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:text="设置"

android:textColor="#82858b" />

</LinearLayout>

</RelativeLayout>

</LinearLayout>

</LinearLayout>

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