[lottery] 06_顶部标题部分管理(一)——配置

Android 4.0

顶部标题部分管理(一)——配置 

注意:在主界面include的时候,一定要设置include的width和height,否则将出现布局混乱
<!-- 1、顶部标题容器 -->
<include
    android:id="@+id/in_main_top_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    layout="@layout/zl_top_title" />
还有merge的区别,只能用在root节点,表示的是当它被include后,merge会被忽略掉,只引用其子节点
步骤:
1、用一个布局文件,里面放着3种不同类型的标题,每次只显示其中的一个
2、标题的分类
①普通标题
    标题内容管理
    帮助和返回按钮显示控制
    步骤:初始化、设置显示内容、设置监听
②未登陆标题
    步骤:初始化、设置监听
③登陆中标题(自动登陆的功能设置后购彩大厅可见,登陆失败后需要切换到登陆标题)
归属到④登陆完成后标题中去管理
④登陆完成后标题
    步骤:初始化、设置显示
3、写一个类TopTitleManager来管理这些标题的显示,隐藏,
以及按钮的监听事件,及文本的显示(id资源,String字符串)
布局:
<?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" >
    <!-- 1、普通标题 -->
    <RelativeLayout
        android:id="@+id/rl_top_common_continer_zl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/id_title_bg"
        android:visibility="visible" >
        <ImageButton
            android:id="@+id/ib_top_return_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:background="@drawable/id_title_goback" />
        <TextView
            android:id="@+id/tv_top_title_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="第20131207期3D选号" />
        <ImageButton
            android:id="@+id/ib_top_help_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:background="@drawable/id_title_help" />
    </RelativeLayout>
    <!-- 2、未登陆标题 -->
    <RelativeLayout
        android:id="@+id/rl_top_unlogin_continer_zl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/id_title_bg"
        android:visibility="invisible" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="3dp"
            android:src="@drawable/id_cmc_logo" />
        <ImageButton
            android:id="@+id/ib_top_register_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="15dip"
            android:layout_marginTop="5dp"
            android:background="@drawable/id_purchase_regist" />
        <ImageButton
            android:id="@+id/ib_top_login_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="10dip"
            android:layout_marginTop="5dp"
            android:layout_toLeftOf="@id/ib_top_register_zl"
            android:background="@drawable/id_purchase_login" />
    </RelativeLayout>
    <!-- 3、登陆完成后标题 -->
    <RelativeLayout
        android:id="@+id/rl_top_login_continer_zl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/id_title_bg"
        android:visibility="gone" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="3dp"
            android:src="@drawable/id_cmc_logo" />
        <ImageButton
            android:id="@+id/ib_purchase_system_info_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:background="@drawable/id_purchase_system_info" />
        <TextView
            android:id="@+id/tv_top_user_info_zl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dip"
            android:layout_toLeftOf="@id/ib_purchase_system_info_zl"
            android:text="@string/is_user_loginned_test" />
    </RelativeLayout>
</RelativeLayout>
结果: