【Android UI设计与开发】第15期:顶部标题栏(六)实现悬浮式顶部和底部标题栏效果

转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9122517      



        这篇文章是实现了百度贴吧一个老版本的悬浮式顶部和底部的标题栏效果,觉得还挺有意思的就想跟大家一起分

享一下,也算是对前面学过的UI设计知识的一个总结吧。好的,话不多说,请大家先看效果图。


一、实现效果图


    


   





二 、项目结构图





三 、详细代码编写


1、主布局Tab选项卡页面,maintabs_activity.xml:

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@android:id/tabhost"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent" >  
  6.   
  7.     <LinearLayout  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="fill_parent"  
  10.         android:background="@color/backgroundcolor"  
  11.         android:orientation="vertical" >  
  12.   
  13.         <FrameLayout  
  14.             android:id="@android:id/tabcontent"  
  15.             android:layout_width="fill_parent"  
  16.             android:layout_height="0.0dip"  
  17.             android:layout_weight="1.0" />  
  18.   
  19.         <TabWidget  
  20.             android:id="@android:id/tabs"  
  21.             android:layout_width="fill_parent"  
  22.             android:layout_height="wrap_content"  
  23.             android:layout_weight="0.0"  
  24.             android:visibility="gone" />  
  25.   
  26.         <FrameLayout  
  27.             android:layout_width="fill_parent"  
  28.             android:layout_height="wrap_content"  
  29.             android:layout_gravity="bottom"  
  30.             android:layout_marginTop="-10.0dip"  
  31.             android:background="@drawable/maintab_toolbar_bg"  
  32.             android:paddingLeft="7.0dip"  
  33.             android:paddingRight="7.0dip" >  
  34.   
  35.             <RadioGroup  
  36.                 android:id="@+id/main_radio"  
  37.                 android:layout_width="fill_parent"  
  38.                 android:layout_height="wrap_content"  
  39.                 android:gravity="center_vertical"  
  40.                 android:orientation="horizontal" >  
  41.   
  42.                 <RadioButton  
  43.                     android:id="@+id/radio_home"  
  44.                     style="@style/main_tab_bottom"  
  45.                     android:drawableTop="@drawable/tabs_home"  
  46.                     android:text="@string/bar" />  
  47.   
  48.                 <RadioButton  
  49.                     android:id="@+id/radio_mention"  
  50.                     style="@style/main_tab_bottom"  
  51.                     android:drawableTop="@drawable/tabs_sort"  
  52.                     android:text="@string/remind" />  
  53.   
  54.                 <RadioButton  
  55.                     android:id="@+id/radio_person_info"  
  56.                     style="@style/main_tab_bottom"  
  57.                     android:drawableTop="@drawable/tabs_search"  
  58.                     android:text="@string/person_info" />  
  59.   
  60.                 <RadioButton  
  61.                     android:id="@+id/radio_more"  
  62.                     style="@style/main_tab_bottom"  
  63.                     android:drawableTop="@drawable/tabs_more"  
  64.                     android:text="@string/more" />  
  65.             </RadioGroup>  
  66.   
  67.             <TextView  
  68.                 android:id="@+id/message_mention"  
  69.                 android:layout_width="wrap_content"  
  70.                 android:layout_height="wrap_content"  
  71.                 android:layout_gravity="top|left|center"  
  72.                 android:layout_marginLeft="115.0dip"  
  73.                 android:layout_marginTop="-5.0dip"  
  74.                 android:background="@drawable/message_tips"  
  75.                 android:gravity="center"  
  76.                 android:textColor="#ffffffff"  
  77.                 android:textSize="10sp"  
  78.                 android:visibility="visible" />  
  79.   
  80.             <TextView  
  81.                 android:id="@+id/message_person"  
  82.                 android:layout_width="wrap_content"  
  83.                 android:layout_height="wrap_content"  
  84.                 android:layout_gravity="top|left|center"  
  85.                 android:layout_marginLeft="190.0dip"  
  86.                 android:layout_marginTop="-5.0dip"  
  87.                 android:background="@drawable/message_tips"  
  88.                 android:gravity="center"  
  89.                 android:textColor="#ffffffff"  
  90.                 android:textSize="13.0sp"  
  91.                 android:visibility="visible" />  
  92.         </FrameLayout>  
  93.     </LinearLayout>  
  94.   
  95. </TabHost>  
2、贴吧首页布局页面,home_activity.xml:
[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     android:background="@color/backgroundcolor"  
  7.     tools:ignore="ContentDescription" >  
  8.   
  9.     <!-- 标题栏 -->  
  10.   
  11.     <LinearLayout  
  12.         android:id="@+id/home_layout_bar"  
  13.         android:layout_width="fill_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:layout_alignParentTop="true"  
  16.         android:layout_gravity="top"  
  17.         android:background="@drawable/title_bg"  
  18.         android:gravity="center" >  
  19.   
  20.         <LinearLayout  
  21.             android:layout_width="fill_parent"  
  22.             android:layout_height="wrap_content"  
  23.             android:background="@drawable/home_topbar_bg"  
  24.             android:gravity="center"  
  25.             android:orientation="horizontal" >  
  26.   
  27.             <!-- 我的贴吧 -->  
  28.   
  29.             <ImageButton  
  30.                 android:id="@+id/home_bt_like"  
  31.                 android:layout_width="fill_parent"  
  32.                 android:layout_height="fill_parent"  
  33.                 android:layout_gravity="center"  
  34.                 android:layout_margin="0.0dip"  
  35.                 android:layout_weight="1.0"  
  36.                 android:background="@null"  
  37.                 android:padding="0.0dip"  
  38.                 android:paddingBottom="2.0dip"  
  39.                 android:scaleType="center"  
  40.                 android:src="@drawable/home_bt_like_on" />  
  41.   
  42.             <!-- 我的标签 -->  
  43.   
  44.             <ImageButton  
  45.                 android:id="@+id/home_bt_mark"  
  46.                 android:layout_width="fill_parent"  
  47.                 android:layout_height="fill_parent"  
  48.                 android:layout_gravity="center"  
  49.                 android:layout_margin="0.0dip"  
  50.                 android:layout_weight="1.0"  
  51.                 android:background="@null"  
  52.                 android:padding="0.0dip"  
  53.                 android:paddingBottom="2.0dip"  
  54.                 android:scaleType="center"  
  55.                 android:src="@drawable/home_bt_mark" />  
  56.         </LinearLayout>  
  57.     </LinearLayout>  
  58.   
  59.     <FrameLayout  
  60.         android:id="@+id/content"  
  61.         android:layout_width="fill_parent"  
  62.         android:layout_height="fill_parent"  
  63.         android:layout_below="@id/home_layout_bar"  
  64.         android:layout_marginTop="-12.0dip" />  
  65.   
  66. </RelativeLayout>  

3、首页贴吧布局页面中的其他两个Activity布局页面,“我的贴吧”Activity布局页面,home_my_activity.xml:

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent" >  
  5.   
  6.     <!-- 我的贴吧页面 -->  
  7.   
  8.     <ImageView  
  9.         android:id="@+id/image_xianjian"  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:src="@drawable/xianjian1"   
  13.         android:visibility="gone" />  
  14.   
  15.     <ProgressBar  
  16.         android:id="@+id/home_progress_like"  
  17.         style="?android:attr/progressBarStyleInverse"  
  18.         android:layout_width="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:layout_gravity="center"  
  21.         android:indeterminateDrawable="@drawable/progressbar"  
  22.         android:visibility="visible" />  
  23.   
  24. </FrameLayout>  

“我的标签”Activity布局页面,home_mark_activity.xml:

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:layout_weight="1.0" >  
  6.   
  7.     <!-- 我的标签页面 -->  
  8.   
  9.     <ImageView  
  10.         android:id="@+id/imageView1"  
  11.         android:layout_width="wrap_content"  
  12.         android:layout_height="wrap_content"  
  13.         android:src="@drawable/xianjian2" />  
  14.   
  15. </FrameLayout>  


4、“提醒”Activity布局页面,mention_activity.xml:

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/mention"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     android:background="#fff1f1f1" >  
  7.   
  8.     <!-- 标题栏 -->  
  9.   
  10.     <LinearLayout  
  11.         android:id="@+id/mention_layout_bar"  
  12.         android:layout_width="fill_parent"  
  13.         android:layout_height="wrap_content"  
  14.         android:layout_alignParentTop="true"  
  15.         android:layout_margin="0.0dip"  
  16.         android:background="@drawable/title_bg" >  
  17.   
  18.         <LinearLayout  
  19.             android:layout_width="fill_parent"  
  20.             android:layout_height="fill_parent"  
  21.             android:layout_margin="0.0dip"  
  22.             android:background="@drawable/home_topbar_bg"  
  23.             android:orientation="horizontal" >  
  24.   
  25.             <Button  
  26.                 android:id="@+id/mention_bt_replyme"  
  27.                 android:layout_width="fill_parent"  
  28.                 android:layout_height="fill_parent"  
  29.                 android:layout_gravity="center"  
  30.                 android:layout_margin="0.0dip"  
  31.                 android:layout_weight="1.0"  
  32.                 android:background="@drawable/home_topbar_bt"  
  33.                 android:clickable="false"  
  34.                 android:gravity="center"  
  35.                 android:padding="0.0dip"  
  36.                 android:paddingBottom="2.0dip"  
  37.                 android:text="@string/mention_replyme"  
  38.                 android:textColor="#ffffffff"  
  39.                 android:textSize="13.0sp" />  
  40.   
  41.             <Button  
  42.                 android:id="@+id/mention_bt_atme"  
  43.                 android:layout_width="fill_parent"  
  44.                 android:layout_height="fill_parent"  
  45.                 android:layout_gravity="center"  
  46.                 android:layout_margin="0.0dip"  
  47.                 android:layout_weight="1.0"  
  48.                 android:background="@null"  
  49.                 android:clickable="true"  
  50.                 android:gravity="center"  
  51.                 android:padding="0.0dip"  
  52.                 android:paddingBottom="2.0dip"  
  53.                 android:text="@string/mention_atme"  
  54.                 android:textColor="#ff90afff"  
  55.                 android:textSize="13.0sp" />  
  56.         </LinearLayout>  
  57.     </LinearLayout>  
  58.   
  59. </RelativeLayout>  

5、“个人资料”布局页面,personalinfo_activity.xml:

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:background="@color/white"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <LinearLayout  
  9.         android:id="@+id/title"  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_alignParentTop="true"  
  13.         android:background="@drawable/title_bg" >  
  14.   
  15.         <Button  
  16.             android:id="@+id/back"  
  17.             style="@style/comm_controls"  
  18.             android:layout_width="wrap_content"  
  19.             android:layout_height="wrap_content"  
  20.             android:layout_gravity="center_vertical"  
  21.             android:layout_marginLeft="3dp"  
  22.             android:background="@drawable/title_back"  
  23.             android:text="@string/back"  
  24.             android:textColor="#ffffffff" />  
  25.   
  26.         <TextView  
  27.             android:id="@+id/titel_text"  
  28.             android:layout_width="wrap_content"  
  29.             android:layout_height="wrap_content"  
  30.             android:layout_gravity="center_vertical"  
  31.             android:layout_weight="1.0"  
  32.             android:gravity="center_horizontal"  
  33.             android:textColor="@color/white"  
  34.             android:visibility="visible" />  
  35.   
  36.         <Button  
  37.             android:id="@+id/home"  
  38.             style="@style/comm_controls"  
  39.             android:layout_width="wrap_content"  
  40.             android:layout_height="wrap_content"  
  41.             android:layout_gravity="center_vertical"  
  42.             android:layout_marginRight="3dp"  
  43.             android:background="@drawable/title_home"  
  44.             android:textColor="#ffffffff" />  
  45.   
  46.         <Button  
  47.             android:id="@+id/refresh"  
  48.             style="@style/comm_controls"  
  49.             android:layout_width="wrap_content"  
  50.             android:layout_height="wrap_content"  
  51.             android:layout_gravity="center_vertical"  
  52.             android:background="@drawable/person_refresh"  
  53.             android:visibility="gone" />  
  54.     </LinearLayout>  
  55.   
  56.     <FrameLayout  
  57.         android:layout_width="fill_parent"  
  58.         android:layout_height="fill_parent"  
  59.         android:layout_marginTop="-14.0dip" >  
  60.   
  61.         <LinearLayout  
  62.             android:layout_width="fill_parent"  
  63.             android:layout_height="fill_parent"  
  64.             android:orientation="vertical" >  
  65.   
  66.             <RelativeLayout  
  67.                 android:id="@+id/info"  
  68.                 android:layout_width="fill_parent"  
  69.                 android:layout_height="90.0dip" >  
  70.   
  71.                 <ImageView  
  72.                     android:id="@+id/photo"  
  73.                     android:layout_width="50.0dip"  
  74.                     android:layout_height="50.0dip"  
  75.                     android:layout_alignParentLeft="true"  
  76.                     android:layout_centerVertical="true"  
  77.                     android:layout_marginLeft="10.0dip"  
  78.                     android:background="@drawable/person_photo_bg"  
  79.                     android:clickable="true"  
  80.                     android:padding="5.0dip"  
  81.                     android:src="@drawable/person_photo" />  
  82.   
  83.                 <LinearLayout  
  84.                     android:id="@+id/buttons"  
  85.                     android:layout_width="wrap_content"  
  86.                     android:layout_height="wrap_content"  
  87.                     android:layout_alignParentRight="true"  
  88.                     android:layout_centerVertical="true"  
  89.                     android:layout_marginRight="13.0dip" >  
  90.   
  91.                     <Button  
  92.                         android:id="@+id/change"  
  93.                         android:layout_width="wrap_content"  
  94.                         android:layout_height="wrap_content"  
  95.                         android:background="@drawable/button_change" />  
  96.   
  97.                     <LinearLayout  
  98.                         android:id="@+id/attention"  
  99.                         android:layout_width="wrap_content"  
  100.                         android:layout_height="wrap_content"  
  101.                         android:clickable="true"  
  102.                         android:gravity="center"  
  103.                         android:minHeight="20.0dip"  
  104.                         android:minWidth="75.0dip"  
  105.                         android:visibility="gone" >  
  106.   
  107.                         <LinearLayout  
  108.                             android:layout_width="wrap_content"  
  109.                             android:layout_height="wrap_content"  
  110.                             android:orientation="horizontal" >  
  111.   
  112.                             <TextView  
  113.                                 android:id="@+id/attention_text"  
  114.                                 android:layout_width="wrap_content"  
  115.                                 android:layout_height="wrap_content"  
  116.                                 android:layout_gravity="center_vertical"  
  117.                                 android:textColor="@color/white"  
  118.                                 android:textSize="15.0sp" />  
  119.   
  120.                             <ProgressBar  
  121.                                 android:id="@+id/attention_progress"  
  122.                                 style="?android:attr/progressBarStyleSmall"  
  123.                                 android:layout_width="wrap_content"  
  124.                                 android:layout_height="wrap_content"  
  125.                                 android:layout_gravity="center_vertical"  
  126.                                 android:layout_marginLeft="3.0dip"  
  127.                                 android:layout_toRightOf="@id/attention_text"  
  128.                                 android:indeterminateDrawable="@drawable/progressbar"  
  129.                                 android:visibility="gone" />  
  130.                         </LinearLayout>  
  131.                     </LinearLayout>  
  132.                 </LinearLayout>  
  133.   
  134.                 <LinearLayout  
  135.                     android:id="@+id/line1"  
  136.                     android:layout_width="wrap_content"  
  137.                     android:layout_height="wrap_content"  
  138.                     android:layout_alignTop="@id/photo"  
  139.                     android:layout_marginLeft="10.0dip"  
  140.                     android:layout_marginRight="10.0dip"  
  141.                     android:layout_marginTop="5.0dip"  
  142.                     android:layout_toLeftOf="@id/buttons"  
  143.                     android:layout_toRightOf="@id/photo"  
  144.                     android:orientation="horizontal" >  
  145.   
  146.                     <LinearLayout  
  147.                         android:layout_width="wrap_content"  
  148.                         android:layout_height="wrap_content" >  
  149.   
  150.                         <TextView  
  151.                             android:id="@+id/name"  
  152.                             android:layout_width="wrap_content"  
  153.                             android:layout_height="wrap_content"  
  154.                             android:layout_weight="1.0"  
  155.                             android:singleLine="true"  
  156.                             android:textColor="@color/black"  
  157.                             android:textSize="15.0sp" />  
  158.   
  159.                         <ImageView  
  160.                             android:id="@+id/sex"  
  161.                             android:layout_width="wrap_content"  
  162.                             android:layout_height="wrap_content"  
  163.                             android:layout_marginLeft="5.0dip"  
  164.                             android:layout_marginTop="2.0dip"  
  165.                             android:layout_weight="0.0" />  
  166.                     </LinearLayout>  
  167.                 </LinearLayout>  
  168.   
  169.                 <TextView  
  170.                     android:id="@+id/intro"  
  171.                     android:layout_width="wrap_content"  
  172.                     android:layout_height="wrap_content"  
  173.                     android:layout_alignLeft="@id/line1"  
  174.                     android:layout_below="@id/line1"  
  175.                     android:layout_marginBottom="10.0dip"  
  176.                     android:layout_marginRight="10.0dip"  
  177.                     android:layout_marginTop="4.0dip"  
  178.                     android:layout_toLeftOf="@id/buttons"  
  179.                     android:singleLine="true"  
  180.                     android:textColor="#ff484848"  
  181.                     android:textSize="13.0dip" />  
  182.             </RelativeLayout>  
  183.   
  184.             <ImageView  
  185.                 android:layout_width="fill_parent"  
  186.                 android:layout_height="wrap_content"  
  187.                 android:scaleType="fitCenter"  
  188.                 android:src="@drawable/list_divider" />  
  189.         </LinearLayout>  
  190.     </FrameLayout>  
  191.   
  192. </LinearLayout>  

6、“更多”布局页面,more_activity.xml:

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:background="@color/backgroundcolor" >  
  6.   
  7.     <!-- 标题栏 -->  
  8.   
  9.     <LinearLayout  
  10.         android:id="@+id/title"  
  11.         android:layout_width="fill_parent"  
  12.         android:layout_height="wrap_content"  
  13.         android:layout_alignParentTop="true"  
  14.         android:layout_gravity="top"  
  15.         android:background="@drawable/title_bg" >  
  16.   
  17.         <TextView  
  18.             android:id="@+id/titel_text"  
  19.             android:layout_width="0dp"  
  20.             android:layout_height="wrap_content"  
  21.             android:layout_gravity="center_vertical"  
  22.             android:layout_marginLeft="10.0dip"  
  23.             android:layout_marginRight="10.0dip"  
  24.             android:layout_weight="1.0"  
  25.             android:gravity="center_horizontal"  
  26.             android:singleLine="true"  
  27.             android:text="@string/more"  
  28.             android:textColor="#ffffffff"  
  29.             android:textSize="15.0sp" />  
  30.     </LinearLayout>  
  31.   
  32. </RelativeLayout>  


7、布局页面就写完了,还有一些自定义按钮的资源文件我就不贴了,有需要的同学可以直接下载源码,下面是Java代码部分,主布局Tab选项卡Activity页面,MainActivity.java:

[java]  view plain copy
  1. package com.yangyu.mytitlebar02;  
  2.   
  3. import android.app.TabActivity;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.widget.CompoundButton;  
  7. import android.widget.CompoundButton.OnCheckedChangeListener;  
  8. import android.widget.RadioButton;  
  9. import android.widget.TabHost;  
  10. import android.widget.TextView;  
  11.   
  12. import com.yangyu.mytitlebar02.home.HomeActivity;  
  13.   
  14. /** 
  15.  * @author yangyu 
  16.  *  功能描述:主Activity程序入口类 
  17.  */  
  18. public class MainActivity extends TabActivity implements OnCheckedChangeListener {  
  19.     //定义Tab选项卡标示符  
  20.     private static final String HOME_TAB = "home_tab";  
  21.     private static final String MENTION_TAB = "mention_tab";  
  22.     private static final String PERSON_TAB = "person_tab";  
  23.     private static final String MORE_TAB = "more_tab";  
  24.   
  25.     //定义Intent对象  
  26.     private Intent mHomeIntent,mMentionIntent,mPersonIntent,mMoreIntent;  
  27.   
  28.     //定义TabHost对象  
  29.     private TabHost mTabHost;  
  30.   
  31.     //定义单选按钮对象  
  32.     private RadioButton homeRb,mentionRb,personRb,moreRb;  
  33.       
  34.     //定义消息提示文本对象  
  35.     private TextView mMessageTipsMention,mMessageTipsPerson;  
  36.   
  37.     @Override  
  38.     public void onCreate(Bundle savedInstanceState) {  
  39.         super.onCreate(savedInstanceState);  
  40.         setContentView(R.layout.maintabs_activity);  
  41.   
  42.         initView();  
  43.           
  44.         initData();  
  45.     }  
  46.       
  47.     /** 
  48.      * 初始化组件 
  49.      */  
  50.     private void initView(){  
  51.         //得到TabHost  
  52.         mTabHost = getTabHost();  
  53.           
  54.         //得到Intent对象  
  55.         mHomeIntent = new Intent(this, HomeActivity.class);  
  56.         mMentionIntent = new Intent(this, MentionActivity.class);  
  57.         mPersonIntent = new Intent(this, PersonInfoActivity.class);  
  58.         mMoreIntent = new Intent(this, MoreActivity.class);  
  59.           
  60.         //得到消息提示文本对象  
  61.         mMessageTipsMention = (TextView) findViewById(R.id.message_mention);  
  62.         mMessageTipsPerson = (TextView) findViewById(R.id.message_person);  
  63.           
  64.         //得到单选按钮对象  
  65.         homeRb = ((RadioButton) findViewById(R.id.radio_home));  
  66.         mentionRb = ((RadioButton) findViewById(R.id.radio_mention));  
  67.         personRb = ((RadioButton) findViewById(R.id.radio_person_info));  
  68.         moreRb = ((RadioButton) findViewById(R.id.radio_more));  
  69.     }  
  70.       
  71.     /** 
  72.      * 初始化数据 
  73.      */  
  74.     private void initData(){  
  75.         //给单选按钮设置监听  
  76.         homeRb.setOnCheckedChangeListener(this);  
  77.         mentionRb.setOnCheckedChangeListener(this);  
  78.         personRb.setOnCheckedChangeListener(this);  
  79.         moreRb.setOnCheckedChangeListener(this);  
  80.           
  81.         //给消息提示文本设置文字  
  82.         mMessageTipsMention.setText("2");  
  83.         mMessageTipsPerson.setText("4");  
  84.           
  85.         //添加进Tab选项卡  
  86.         mTabHost.addTab(buildTabSpec(HOME_TAB, mHomeIntent));  
  87.         mTabHost.addTab(buildTabSpec(MENTION_TAB, mMentionIntent));  
  88.         mTabHost.addTab(buildTabSpec(PERSON_TAB, mPersonIntent));  
  89.         mTabHost.addTab(buildTabSpec(MORE_TAB, mMoreIntent));  
  90.           
  91.         //设置当前默认的Tab选项卡页面  
  92.         homeRb.setChecked(true);  
  93.         mTabHost.setCurrentTabByTag(HOME_TAB);            
  94.     }                         
  95.   
  96.     private TabHost.TabSpec buildTabSpec(String tag, Intent intent) {  
  97.         TabHost.TabSpec tabSpec = mTabHost.newTabSpec(tag);  
  98.         tabSpec.setContent(intent).setIndicator("");  
  99.           
  100.         return tabSpec;  
  101.     }  
  102.   
  103.     /** 
  104.      * Tab按钮选中监听事件 
  105.      */  
  106.     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {  
  107.         if (isChecked) {  
  108.             switch (buttonView.getId()) {  
  109.             case R.id.radio_home:  
  110.                 mTabHost.setCurrentTabByTag(HOME_TAB);  
  111.                 break;  
  112.             case R.id.radio_mention:  
  113.                 mTabHost.setCurrentTabByTag(MENTION_TAB);  
  114.                 //VISIBLE:0  意思是可见的;INVISIBILITY:4 意思是不可见的,但还占着原来的空间;GONE:8  意思是不可见的,不占用原来的布局空间   
  115.                 mMessageTipsMention.setVisibility(8);  
  116.                 break;  
  117.             case R.id.radio_person_info:  
  118.                 mTabHost.setCurrentTabByTag(PERSON_TAB);  
  119.                 mMessageTipsPerson.setVisibility(8);  
  120.                 break;  
  121.             case R.id.radio_more:  
  122.                 mTabHost.setCurrentTabByTag(MORE_TAB);  
  123.                 break;  
  124.             default:  
  125.                 break;  
  126.             }  
  127.         }  
  128.     }         
  129.       
  130. }  

8、贴吧首页Activity页面,HomeActivity.java:

[java]  view plain copy
  1. package com.yangyu.mytitlebar02.home;  
  2.   
  3. import android.app.ActivityGroup;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.widget.FrameLayout;  
  9. import android.widget.ImageButton;  
  10.   
  11. import com.yangyu.mytitlebar02.R;  
  12.   
  13. /** 
  14.  * @author yangyu 
  15.  *  功能描述:贴吧首页Activity页面 
  16.  */  
  17. public class HomeActivity extends ActivityGroup implements OnClickListener{  
  18.     //定义帧布局对象  
  19.     private FrameLayout mContent;  
  20.       
  21.     //定义图片按钮对象  
  22.     private ImageButton myButton,markButton;  
  23.       
  24.     //定义标示符  
  25.     private static final String HOME_LIKE_ID = "like";  
  26.     private static final String HOME_MARK_ID = "mark";   
  27.   
  28.     @Override  
  29.     protected void onCreate(Bundle savedInstanceState) {  
  30.         super.onCreate(savedInstanceState);  
  31.         setContentView(R.layout.home_activity);  
  32.           
  33.         mContent = (FrameLayout) findViewById(R.id.content);  
  34.           
  35.         //得到按钮对象  
  36.         myButton = (ImageButton) findViewById(R.id.home_bt_like);  
  37.         markButton = (ImageButton) findViewById(R.id.home_bt_mark);  
  38.           
  39.         //按钮设置监听  
  40.         myButton.setOnClickListener(this);  
  41.         markButton.setOnClickListener(this);      
  42.           
  43.         //初始化默认显示的页面  
  44.         showMyView();  
  45.     }  
  46.       
  47.     /** 
  48.      * 添加视图 
  49.      */  
  50.     public void addView(String id, Class<?> clazz) {  
  51.         Intent intent = new Intent(this, clazz);  
  52.         //移除这个布局中所有的组件  
  53.         mContent.removeAllViews();  
  54.         mContent.addView(getLocalActivityManager().startActivity(id, intent).getDecorView());  
  55.     }     
  56.   
  57.     @Override  
  58.     public void onClick(View v) {  
  59.         switch (v.getId()) {  
  60.         case R.id.home_bt_like:  
  61.             showMyView();  
  62.             break;  
  63.         case R.id.home_bt_mark:  
  64.             showMarkView();  
  65.             break;  
  66.         default:  
  67.             break;  
  68.         }  
  69.     }  
  70.   
  71.     /** 
  72.      * 显示我的贴吧页面 
  73.      */  
  74.     private void showMyView(){  
  75.         addView(HOME_LIKE_ID, MyActivity.class);  
  76.         myButton.setBackgroundResource(R.drawable.home_topbar_bt);  
  77.         myButton.setImageResource(R.drawable.home_bt_like_on);  
  78.         markButton.setBackgroundDrawable(null);  
  79.         markButton.setImageResource(R.drawable.home_bt_mark);  
  80.     }  
  81.       
  82.     /** 
  83.      * 显示我的标签页面 
  84.      */  
  85.     private void showMarkView(){  
  86.         addView(HOME_MARK_ID, MarkActivity.class);  
  87.         markButton.setBackgroundResource(R.drawable.home_topbar_bt);  
  88.         markButton.setImageResource(R.drawable.home_bt_mark_on);  
  89.         myButton.setBackgroundDrawable(null);  
  90.         myButton.setImageResource(R.drawable.home_bt_like);  
  91.     }  
  92. }  

9、其他的Activity代码我就不贴了,都只是加载了一个布局,例如“提醒”Activity页面,MentionActivity.java:

[java]  view plain copy
  1. package com.yangyu.mytitlebar02;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5.   
  6. /** 
  7.  * @author yangyu 
  8.  *  功能描述:提醒Activity页面 
  9.  */  
  10. public class MentionActivity extends Activity {  
  11.   
  12.     @Override  
  13.     protected void onCreate(Bundle savedInstanceState) {  
  14.         super.onCreate(savedInstanceState);  
  15.         setContentView(R.layout.mention_activity);  
  16.     }  
  17.       
  18. }  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值