Android学习--底部导航Fragment填充

本文介绍了Android新手如何实现底部导航栏的基本框架,使用Fragment填充内容。通过创建主布局、子Fragment布局和底部样式,结合MainActivity.java中的代码逻辑,实现消息、联系人、动态三个页面的切换。主要涉及底部导航栏布局设计、Fragment管理和按钮监听事件处理。
摘要由CSDN通过智能技术生成

很多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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值