直接看栗子吧,效果基本实现,界面微调和弹窗的优化,去做的话会很耗时说,暂时就酱紫了。上传效果动态图太大了,直接手机截图的效果图如下:

至于代码的实现主要就是自定义的菜单栏,和用 PopupWindow 实现弹窗了。仔细看代码很好懂的。

1.主界面布局代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <FrameLayout
android:id="@+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/frameMenu"
android:layout_alignParentTop="true" >
</FrameLayout> <FrameLayout
android:id="@+id/frameMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/skin_tabbar_bg"
android:orientation="horizontal" > <!-- 动态 --> <FrameLayout
android:id="@+id/layout_at"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageView
android:id="@+id/image_at"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:src="@drawable/skin_tabbar_icon_auth_select" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:text="@string/skin_tabbar_icon_auth"
android:textColor="@android:color/black"
android:textSize="12sp" />
</FrameLayout> <!-- 与我相关 --> <FrameLayout
android:id="@+id/layout_auth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageView
android:id="@+id/image_auth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:src="@drawable/skin_tabbar_icon_at_select" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:text="@string/skin_tabbar_icon_at"
android:textColor="@android:color/black"
android:textSize="12sp" />
</FrameLayout> <!-- 留白 --> <FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</FrameLayout> <!-- 我的空间 --> <FrameLayout
android:id="@+id/layout_space"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageView
android:id="@+id/image_space"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:src="@drawable/skin_tabbar_icon_space_select" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:text="@string/skin_tabbar_icon_space"
android:textColor="@android:color/black"
android:textSize="12sp" />
</FrameLayout> <!-- 玩吧 --> <FrameLayout
android:id="@+id/layout_more"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" > <ImageView
android:id="@+id/image_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:src="@drawable/skin_tabbar_icon_more_select" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:text="@string/skin_tabbar_icon_more"
android:textColor="@android:color/black"
android:textSize="12sp" />
</FrameLayout>
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@android:color/black" >
</LinearLayout>
</FrameLayout> <!-- 中间按钮背景 --> <ImageView
android:id="@+id/toggle_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/frameMenu"
android:layout_centerInParent="true"
android:src="@drawable/skin_tabbar_btn" /> <!-- 中间按钮 --> <ImageView
android:id="@+id/plus_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/frameMenu"
android:layout_centerInParent="true"
android:src="@drawable/skin_tabbar_icon_select" /> </RelativeLayout>

activity_main.xml

2.弹窗布局,就是几个图标的显示,比较简单的,可以看代码

3.然后就是主界面逻辑代码了,菜单栏按钮事件控制页面的显示,可以图标的选中状态,已经弹窗的实现,代码如下:

package com.yanis.yc_ui_qzone;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener; public class MainActivity extends FragmentActivity implements OnClickListener {
// 定义Fragment页面
private FragmentAt fragmentAt;
private FragmentAuth fragmentAuth;
private FragmentSpace fragmentSpace;
private FragmentMore fragmentMore;
// 定义布局对象
private FrameLayout atFl, authFl, spaceFl, moreFl; // 定义图片组件对象
private ImageView atIv, authIv, spaceIv, moreIv; // 定义按钮图片组件
private ImageView toggleImageView, plusImageView; // 定义PopupWindow
private PopupWindow popWindow;
// 获取手机屏幕分辨率的类
private DisplayMetrics dm; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initView(); initData(); // 初始化默认为选中点击了“动态”按钮
clickAtBtn();
} /**
* 初始化组件
*/
private void initView() {
// 实例化布局对象
atFl = (FrameLayout) findViewById(R.id.layout_at);
authFl = (FrameLayout) findViewById(R.id.layout_auth);
spaceFl = (FrameLayout) findViewById(R.id.layout_space);
moreFl = (FrameLayout) findViewById(R.id.layout_more); // 实例化图片组件对象
atIv = (ImageView) findViewById(R.id.image_at);
authIv = (ImageView) findViewById(R.id.image_space);
spaceIv = (ImageView) findViewById(R.id.image_space);
moreIv = (ImageView) findViewById(R.id.image_more); // 实例化按钮图片组件
toggleImageView = (ImageView) findViewById(R.id.toggle_btn);
plusImageView = (ImageView) findViewById(R.id.plus_btn); } /**
* 初始化数据
*/
private void initData() {
// 给布局对象设置监听
atFl.setOnClickListener(this);
authFl.setOnClickListener(this);
spaceFl.setOnClickListener(this);
moreFl.setOnClickListener(this); // 给按钮图片设置监听
toggleImageView.setOnClickListener(this);
} /**
* 点击事件
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
// 点击动态按钮
case R.id.layout_at:
clickAtBtn();
break;
// 点击与我相关按钮
case R.id.layout_auth:
clickAuthBtn();
break;
// 点击我的空间按钮
case R.id.layout_space:
clickSpaceBtn();
break;
// 点击更多按钮
case R.id.layout_more:
clickMoreBtn();
break;
// 点击中间按钮
case R.id.toggle_btn:
clickToggleBtn();
break;
}
} /**
* 点击了“动态”按钮
*/
private void clickAtBtn() {
// 实例化Fragment页面
fragmentAt = new FragmentAt();
// 得到Fragment事务管理器
FragmentTransaction fragmentTransaction = this
.getSupportFragmentManager().beginTransaction();
// 替换当前的页面
fragmentTransaction.replace(R.id.frame_content, fragmentAt);
// 事务管理提交
fragmentTransaction.commit();
// 改变选中状态
atFl.setSelected(true);
atIv.setSelected(true); authFl.setSelected(false);
authIv.setSelected(false); spaceFl.setSelected(false);
spaceIv.setSelected(false); moreFl.setSelected(false);
moreIv.setSelected(false);
} /**
* 点击了“与我相关”按钮
*/
private void clickAuthBtn() {
// 实例化Fragment页面
fragmentAuth = new FragmentAuth();
// 得到Fragment事务管理器
FragmentTransaction fragmentTransaction = this
.getSupportFragmentManager().beginTransaction();
// 替换当前的页面
fragmentTransaction.replace(R.id.frame_content, fragmentAuth);
// 事务管理提交
fragmentTransaction.commit(); atFl.setSelected(false);
atIv.setSelected(false); authFl.setSelected(true);
authIv.setSelected(true); spaceFl.setSelected(false);
spaceIv.setSelected(false); moreFl.setSelected(false);
moreIv.setSelected(false);
} /**
* 点击了“我的空间”按钮
*/
private void clickSpaceBtn() {
// 实例化Fragment页面
fragmentSpace = new FragmentSpace();
// 得到Fragment事务管理器
FragmentTransaction fragmentTransaction = this
.getSupportFragmentManager().beginTransaction();
// 替换当前的页面
fragmentTransaction.replace(R.id.frame_content, fragmentSpace);
// 事务管理提交
fragmentTransaction.commit(); atFl.setSelected(false);
atIv.setSelected(false); authFl.setSelected(false);
authIv.setSelected(false); spaceFl.setSelected(true);
spaceIv.setSelected(true); moreFl.setSelected(false);
moreIv.setSelected(false);
} /**
* 点击了“更多”按钮
*/
private void clickMoreBtn() {
// 实例化Fragment页面
fragmentMore = new FragmentMore();
// 得到Fragment事务管理器
FragmentTransaction fragmentTransaction = this
.getSupportFragmentManager().beginTransaction();
// 替换当前的页面
fragmentTransaction.replace(R.id.frame_content, fragmentMore);
// 事务管理提交
fragmentTransaction.commit(); atFl.setSelected(false);
atIv.setSelected(false); authFl.setSelected(false);
authIv.setSelected(false); spaceFl.setSelected(false);
spaceIv.setSelected(false); moreFl.setSelected(true);
moreIv.setSelected(true);
} /**
* 点击了中间按钮
*/
private void clickToggleBtn() {
showPopupWindow(toggleImageView);
// 改变按钮显示的图片为按下时的状态
plusImageView.setSelected(true);
} /**
* 改变显示的按钮图片为正常状态
*/
private void changeButtonImage() {
plusImageView.setSelected(false);
} /**
* 显示PopupWindow弹出菜单
*/
private void showPopupWindow(View parent) {
if (popWindow == null) {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.popwindow_layout, null);
dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
// 创建一个PopuWidow对象
popWindow = new PopupWindow(view, dm.widthPixels, LinearLayout.LayoutParams.WRAP_CONTENT);
}
// 使其聚集 ,要想监听菜单里控件的事件就必须要调用此方法
popWindow.setFocusable(true);
// 设置允许在外点击消失
popWindow.setOutsideTouchable(true);
// 设置背景,这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
popWindow.setBackgroundDrawable(new BitmapDrawable());
// PopupWindow的显示及位置设置
// popWindow.showAtLocation(parent, Gravity.FILL, 0, 0);
popWindow.showAsDropDown(parent, 0,0); popWindow.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
// 改变显示的按钮图片为正常状态
changeButtonImage();
}
}); // 监听触屏事件
popWindow.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
// 改变显示的按钮图片为正常状态
changeButtonImage();
popWindow.dismiss();
return false;
}
});
}
}

MainActivity

4.其他的请看源代码吧 o(∩_∩)o

源代码地址:https://github.com/YeXiaoChao/Yc_ui_fragment_qzone

【Android UI设计与开发】6.底部菜单栏(三)使用Fragment+PopupWindow仿QQ空间最新版底部菜单栏的更多相关文章

  1. 【Android UI设计与开发】第05期:引导界面(五)实现应用程序只启动一次引导界面

    [Android UI设计与开发]第05期:引导界面(五)实现应用程序只启动一次引导界面 jingqing 发表于 2013-7-11 14:42:02 浏览(229501) 这篇文章算是对整个引导界 ...

  2. 【转】【Android UI设计与开发】之详解ActionBar的使用,androidactionbar

    原文网址:http://www.bkjia.com/Androidjc/895966.html [Android UI设计与开发]之详解ActionBar的使用,androidactionbar 详解 ...

  3. 【Android UI设计与开发】第02期:引导界面(二)使用ViewPager实现欢迎引导页面

    本系列文章都会以一个程序的实例开发为主线来进行讲解,以求达到一个循序渐进的学习效果,这样更能加深大家对于程序为什么要这样写的用意,理论加上实际的应用才能达到事半功倍的效果,不是吗? 最下方有源码的下载 ...

  4. 【Android UI设计与开发】5.底部菜单栏(二)使用Fragment实现底部菜单栏

    既然 Fragment 取代了TabActivity,当然 TabActivity 的能实现的菜单栏,Fragment 当然也能实现.主要其实就是通过菜单栏的点击事件切换 Fragment 的显示和隐 ...

  5. 【转】【Android UI设计与开发】第07期:底部菜单栏(二)Fragment的详细介绍和使用方法

    原始地址:http://blog.csdn.net/yangyu20121224/article/category/1431917/1 由于TabActivity在Android4.0以后已经被完全弃 ...

  6. 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单

    前一篇文章中有用到 PopupWindow 来实现弹窗的功能.简单介绍以下吧. 官方文档是这样解释的:这就是一个弹出窗口,可以用来显示一个任意视图.出现的弹出窗口是一个浮动容器的当前活动. 1.首先来 ...

  7. 【Android UI设计与开发】9:滑动菜单栏(一)开源项目SlidingMenu的使用和示例

    一.SlidingMenu简介 相信大家对SlidingMenu都不陌生了,它是一种比较新的设置界面或配置界面的效果,在主界面左滑或者右滑出现设置界面效果,能方便的进行各种操作.很多优秀的应用都采用了 ...

  8. 【Android UI设计与开发】8.顶部标题栏(一)ActionBar 奥义·详解

    一.ActionBar介绍 在Android 3.0中除了我们重点讲解的Fragment外,Action Bar也是一个非常重要的交互元素,Action Bar取代了传统的tittle bar和men ...

  9. 【Android UI设计与开发】第01期:引导界面(一)ViewPager介绍和使用详解

    做Android开发加起来差不多也有一年多的时间了,总是想写点自己在开发中的心得体会与大家一起交流分享.共同进步,刚开始写也不知该如何下手,仔细想了一下,既然是刚开始写,那就从一个软件给人最直观的感受 ...

随机推荐

  1. MySQL备份与恢复

    1.通过mysqldump命令进行数据备份 mysql数据库的备份采用直接打包数据库文件夹(注:InnoDB引擎不支持直接拷贝数据文件备份数据库,由于使用InnoDB引擎的库或表是不能使用此种方式): ...

  2. PUT 还是 POST ?

    http://www.oschina.net/translate/put-or-post http://my.oschina.net/u/1263964/blog/268932 这两个方法咋一看都可以 ...

  3. C++ Qt 框架静态编译 操作记录

    谁愿意写个程式出来之后还附带一堆DLL,尤其是名字如此明显的名字. 于是在网上看了看,是需要下载源代码然后进行编译的,但是看了看别人说的编译时间,长达几个小时,瞬间就感觉不想做了.因为我还需要抓紧时间 ...

  4. Ubuntu14.04安装ROOT集群

    之前尝试在CentOS7上部署ROOT集群,却发现无论是源码包安装,还是官方提供的二进制包,都缺少了关键的xproofd可执行文件,导致PoD不能运行.没有办法,只能尝试在其他OS上部署,这里我选择了 ...

  5. 【GPU编解码】GPU硬解码---DXVA

    前面介绍利用NVIDIA公司提供的CUVID库进行视频硬解码,下面将介绍利用DXVA进行硬解码. 一.DXVA介绍 DXVA是微软公司专门定制的视频加速规范,是一种接口规范.DXVA规范制定硬件加速解 ...

  6. 自定义View_1_关于View,ViewGroup的测量和绘制流程

    自定义View(1) ------ 关于View,ViewGroup的测量和绘制流程 在Android当中,自定义控件属于比较高级的知识体系,今天我们就一起研究研究关于自定义View的那点事,看看它到 ...

  7. C#内存占用大量资源的解决办法

    昨天,独立完成了一个项目,一直运行起,起初运行内存为15Mb左右,但是发现内存以每秒2Mb的速度增加,吓了我一跳(注:我实习生,我的工作中第一个项目).从头找寻对象,再来dispose,弄得我晕头转向 ...

  8. CRM 2013 Reporting Extensions for SSRS 安装及问题解决

    说明一下 Reporting Extensions for SSRS 安装过程. 安装目录在安装目录下 SrsDataConnector 下.如果是CRM 2013安装中运行,可以跳过此步. 此外在说 ...

  9. SharePoint 2013 中的SQL Server 安全

    使用SharePoint很长时间以来,都认为Sql只需要最初始的配置,即不再需要管理和维护:而事实上,Sql的管理和安全,都是和SharePoint环境的稳定性息息相关的,所以,要绝对重视ShareP ...

  10. android assets文件夹资源的访问

    1.assets文件夹里面的文件都是保持原始的文件格式 . 2.assets中的文件只可以读取而不能进行写的操作. 3.assets目录下的资源文件不会在R.java自动生成ID,所以读取assets ...