安卓APP底部导航栏(有消息圆点指示器),实现fragment切换(eclipse)

本文介绍了如何使用相对布局和单选按钮在安卓应用中实现底部导航栏,包括消息圆点指示器。通过设置选择器控制状态切换,使用Fragment进行页面动态添加、删除和替换。同时提供了fragment的切换方法和代码重构的实践建议。

本项目使用了相对布局和单选按钮实现了安卓app常见的底部导航栏(带有消息圆点指示器),效果如果所示


一、布局代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >


    <!-- Fragment显示内容的容器 -->
    <FrameLayout
        android:id="@+id/fl_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/nav_layout" />
    
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_above="@+id/nav_layout"
        android:background="@color/line_bg" />


    <LinearLayout
    android:id="@+id/nav_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">
    <!-- 首页 -->
   <RelativeLayout
       android:id="@+id/rlHomePage"
       android:layout_width="0dp"
       android:layout_height="match_parent"
       android:padding="2dp"
       android:background="@drawable/selector_nav_rl"
       android:layout_weight="2">


       <RadioButton
           android:id="@+id/rbtnHomePage"
           style="@style/nav_radio_style"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_centerInParent="true"
           android:checked="true"
           android:drawableTop="@drawable/selector_home_page"
           android:text="首页"
           android:textColor="@color/nav_selector_text_color" />

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值