很多APP都会有一个底部导航栏,作为一开始接触Android的新手,学习基本的框架基础,对这些要有一定的了解,这里是笔者就类似QQ的消息、联系人、动态三个底部导航的简单框架代码的一个整理和分享。 笔者在这里采用的是fragment碎片填充的方法。
先看布局
一个主布局mainfragment,三个子页面的fragment布局,还有一个单独写的bottombar底部样式。
在mainfragment.xml中,引用了framelayout布局,和底部bottombar.
<?xml version="1.0" encoding="utf-8"?>
<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/frame_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</FrameLayout>
<include
android:id="@+id/include_bottombar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/bottombar"/>
</LinearLayout>
在bottombar.xml中,设置消息,联系人,动态的背景图片和文字,加载到上述的mainfragment.xml文件中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/my_view_color" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/view1"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_xi