今天给大家分享的是Apad Qzone的UI框架,我们首先看下交互图如下:

图1:交互效果图.

从上图可以看出,整个应用其实UI框架相对比较简单,可以分为俩部分,左侧导航栏区域,右侧显示内容区域。当我们点击左侧导航栏时,右侧显示相对应内容。

应用的主要内容分为四个模块:好友动态;个人主页;好友列表;应用中心。右侧显示内容则统一由一个管理器管理,管理器管理了右侧的容器以及显示内容面板。

也许用文字不太好说清楚,所以我写了一个简单的Demo以及画了一个UI结构图方便大家理解:

首先是新建一个Android工程,命名为QzoneFrameDemo,结构如下:

图2:程序代码结构图:

为了更容易理解代码,我画了一个各个类的关系图如下:

上图可以清晰的看清各个类之间的关系,其中QZRightWindowManger管理了QZRightWindowContainer(剪头忘记加了)和右侧的四个Window,QZRightWindowContainer继承了FrameLayout,四个Window继承了QZRightWindowBase。

其中QZRightWindowContainer代码如下(继承了FrameLayout):

[java] view plaincopy
  1. package com.tutor.frame;
  2. import android.content.Context;
  3. import android.util.AttributeSet;
  4. import android.widget.FrameLayout;
  5. public class QZRightWindowContainer extends FrameLayout {
  6. public QZRightWindowContainer(Context context){
  7. super(context);
  8. }
  9. public QZRightWindowContainer(Context context, AttributeSet attrs) {
  10. super(context, attrs);
  11. }
  12. }

而右侧四个Window的基类QZRightWindowBase的代码如下:

[java] view plaincopy
  1. package com.tutor.frame;
  2. import android.content.Context;
  3. import android.util.AttributeSet;
  4. import android.widget.FrameLayout;
  5. import android.widget.TextView;
  6. public abstract class QZRightWindowBase extends FrameLayout {
  7. public TextView mContentTextView;
  8. private LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
  9. LayoutParams.FILL_PARENT);
  10. public QZRightWindowBase(Context context){
  11. super(context);
  12. setupViews();
  13. }
  14. public QZRightWindowBase(Context context, AttributeSet attrs) {
  15. super(context, attrs);
  16. setupViews();
  17. }
  18. private void setupViews(){
  19. mContentTextView = new TextView(getContext());
  20. mContentTextView.setLayoutParams(params);
  21. }
  22. //做些事为了扩展举例而已
  23. public abstract void dosomething();
  24. //做些事2
  25. public abstract void dosomething2();
  26. }

右侧窗口Window1即QZRightWindow1代码(其他的都一样不贴代码了)如下:

[java] view plaincopy
  1. package com.tutor.frame;
  2. import android.content.Context;
  3. import android.graphics.Color;
  4. import android.util.AttributeSet;
  5. public class QZRightWindow1 extends QZRightWindowBase{
  6. public QZRightWindow1(Context context){
  7. super(context);
  8. setupViews();
  9. }
  10. public QZRightWindow1(Context context, AttributeSet attrs) {
  11. super(context, attrs);
  12. setupViews();
  13. }
  14. private void setupViews(){
  15. mContentTextView.setText("好友动态");
  16. mContentTextView.setBackgroundColor(Color.RED);
  17. addView(mContentTextView);
  18. }
  19. @Override
  20. public void dosomething() {
  21. // TODO Auto-generated method stub
  22. }
  23. @Override
  24. public void dosomething2() {
  25. // TODO Auto-generated method stub
  26. }
  27. }

管理QZRightWindowContainer和右侧四个Window的管理类QZRightWindowManager代码如下:

[java] view plaincopy
  1. package com.tutor.frame;
  2. import java.util.HashMap;
  3. import java.util.Iterator;
  4. import android.view.View;
  5. public class QZRightWindowManager {
  6. /**
  7. * 好友动态面板的KEY
  8. */
  9. public static final int FRIEND_TRENDS_WINDOW = 0;
  10. /**
  11. * 个人中心面板的KEY
  12. */
  13. public static final int HOME_PAGE_WINDOW = 1;
  14. /**
  15. * 好友关系链面板的KEY
  16. */
  17. public static final int FRIEND_LIST_WINDOW = 2;
  18. /**
  19. * 应用中心面板的KEY
  20. */
  21. public static final int APP_CENTER_WINDOW = 3;
  22. private HashMap<Integer, QZRightWindowBase> mHashMap;
  23. private QZRightWindowContainer mContainer;
  24. public QZRightWindowManager(){
  25. mHashMap = new HashMap<Integer, QZRightWindowBase>();
  26. }
  27. public void setmContainer(QZRightWindowContainer container) {
  28. this.mContainer = container;
  29. }
  30. public void showRightWindow(int num,QZRightWindowBase mQzRightWindowBase){
  31. if(!mHashMap.containsKey(num)){
  32. mHashMap.put(num, mQzRightWindowBase);
  33. if(!(mQzRightWindowBase instanceof QZRightWindow1)){
  34. mContainer.addView(mQzRightWindowBase);
  35. }
  36. }
  37. for (Iterator iter = mHashMap.keySet().iterator(); iter.hasNext();) {
  38. Object key = iter.next();
  39. QZRightWindowBase qzb = mHashMap.get(key);
  40. qzb.setVisibility(View.INVISIBLE);
  41. }
  42. mQzRightWindowBase.setVisibility(View.VISIBLE);
  43. }
  44. }

主程序QzoneFrameDemoActivity代码如下:

[java] view plaincopy
  1. package com.tutor.framedemo;
  2. import com.tutor.frame.QZLeftNavBar;
  3. import com.tutor.frame.QZRightWindow1;
  4. import com.tutor.frame.QZRightWindow2;
  5. import com.tutor.frame.QZRightWindow3;
  6. import com.tutor.frame.QZRightWindow4;
  7. import com.tutor.frame.QZRightWindowBase;
  8. import com.tutor.frame.QZRightWindowContainer;
  9. import com.tutor.frame.QZRightWindowManager;
  10. import android.app.Activity;
  11. import android.os.Bundle;
  12. import android.view.View;
  13. import android.view.View.OnClickListener;
  14. public class QzoneFrameDemoActivity extends Activity implements OnClickListener{
  15. private QZRightWindow1 mQzRightWindow1;
  16. private QZRightWindow2 mQzRightWindow2;
  17. private QZRightWindow3 mQzRightWindow3;
  18. private QZRightWindow4 mQzRightWindow4;
  19. private QZLeftNavBar mQzLeftNavBar;
  20. private QZRightWindowContainer mQzRightWindowContainer;
  21. private QZRightWindowManager mQzRightWindowManager;
  22. @Override
  23. public void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.main);
  26. setupViews();
  27. }
  28. private void setupViews(){
  29. mQzRightWindowManager = new QZRightWindowManager();
  30. mQzLeftNavBar = (QZLeftNavBar)findViewById(R.id.navbar);
  31. mQzLeftNavBar.findViewById(R.id.rw1).setOnClickListener(this);
  32. mQzLeftNavBar.findViewById(R.id.rw2).setOnClickListener(this);
  33. mQzLeftNavBar.findViewById(R.id.rw3).setOnClickListener(this);
  34. mQzLeftNavBar.findViewById(R.id.rw4).setOnClickListener(this);
  35. mQzRightWindow1 = (QZRightWindow1)findViewById(R.id.qzrw1);
  36. mQzRightWindowContainer = (QZRightWindowContainer)findViewById(R.id.container);
  37. mQzRightWindowManager.setmContainer(mQzRightWindowContainer);
  38. }
  39. private void showRightWindow(int num,QZRightWindowBase mQzRightWindowBase){
  40. mQzRightWindowManager.showRightWindow(num, mQzRightWindowBase);
  41. }
  42. @Override
  43. public void onClick(View v) {
  44. int id = v.getId();
  45. switch (id) {
  46. case R.id.rw1:
  47. showRightWindow(QZRightWindowManager.FRIEND_TRENDS_WINDOW, mQzRightWindow1);
  48. break;
  49. case R.id.rw2:
  50. if(mQzRightWindow2 == null){
  51. mQzRightWindow2 = new QZRightWindow2(this);
  52. }
  53. showRightWindow(QZRightWindowManager.HOME_PAGE_WINDOW, mQzRightWindow2);
  54. break;
  55. case R.id.rw3:
  56. if(mQzRightWindow3 == null){
  57. mQzRightWindow3 = new QZRightWindow3(this);
  58. }
  59. showRightWindow(QZRightWindowManager.FRIEND_LIST_WINDOW, mQzRightWindow3);
  60. break;
  61. case R.id.rw4:
  62. if(mQzRightWindow4 == null){
  63. mQzRightWindow4 = new QZRightWindow4(this);
  64. }
  65. showRightWindow(QZRightWindowManager.APP_CENTER_WINDOW, mQzRightWindow4);
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. }

主程序所用到的布局文件main.xml代码如下:

[java] view plaincopy
  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:orientation="horizontal" >
  6. <com.tutor.frame.QZLeftNavBar
  7. android:id="@+id/navbar"
  8. android:layout_width="wrap_content"
  9. android:layout_height="fill_parent"/>
  10. <com.tutor.frame.QZRightWindowContainer
  11. android:id="@+id/container"
  12. android:layout_width="fill_parent"
  13. android:layout_height="fill_parent"
  14. >
  15. <com.tutor.frame.QZRightWindow1
  16. android:id="@+id/qzrw1"
  17. android:layout_width="fill_parent"
  18. android:layout_height="fill_parent"
  19. />
  20. </com.tutor.frame.QZRightWindowContainer>
  21. </LinearLayout>

运行效果如下:

效果1

效果2.

OK,这样就大功告成了!对于pad上面的应用,单Activity化,各个功能模块化,UI控件化,是比较好的选择,这样可以加大开发效率,减少和其他同学的耦合性。

下面的链接是源代码,供新手们学习用,今天就讲到这里,谢谢大家!!!

源代码点击进入==>

转自:http://blog.csdn.net/android_tutor/article/details/7170434

(转)Android QQ空间(Apad)项目总结(三)---应用UI框架的搭建!!!相关推荐

  1. Android QQ空间(Apad)项目总结(三)---应用UI框架的搭建!!!

    大家好,今天是元旦节了,祝大家节日快乐!今天给大家分享的是Apad Qzone的UI框架,我们首先看下交互图如下: 图1:交互效果图. 从上图可以看出,整个应用其实UI框架相对比较简单,可以分为俩部分 ...

  2. Android QQ空间说说回复功能简介

    Android QQ空间说说回复功能简介 好久没有写博客了,主要最近项目太忙,而且都是一些没有技术含量的东西,所以写的就比较少. 最近项目里面有很多关于textview的样式问题,比如一些字体设置了背 ...

  3. android qq1像素页面,Android QQ空间1.2体验

    下载安装后,发现Android空间UI很简洁漂亮,气泡提示新消息.手写字体都非常不错.还有几个方便手机用户随时分享的小窍门:桌面widget直接发带图说说并可同步到QQ签名和微博.手机拍照直接发空间手 ...

  4. android qq空间效果,更新UI设计 Android手机QQ空间1.2详测

    近日,腾讯发布了Android手机QQ空间1.2版.经过一周的试用,小编认为该版QQ空间的多项创新,大大地发挥了Android平台的价值. 从测试结果来看,Android手机QQ空间1.2版在原有便捷 ...

  5. QQ空间常遇到的三个问题及解决办法

    QQ空间常遇到的三个问题及解决办法 你的QQ空间用起来有问题?如果您在使用QQ空间过程中发现了问题,又解决不了,不如看看腾讯官方的QQ空间QZone访问的系列问题解决办法,也许能快速找到窍门. Q:我 ...

  6. android qq空间 sdk,Android中使用腾讯的SDK完成分享图文到qq空间

    1.首先在腾讯开放平台中注册APP_ID,下载SDK并导入到应用程序 2.开始分享图文到qq空间 /** * 分享歌曲到qzone */ private void share2qzone() { fi ...

  7. android qq空间相册,QQ空间Android3.3发布 新增空间、相册权限设置

    现代社会人们越来越注重对自己隐私的保护,即使在虚拟环境中,人们还是会尽可能的为自己划出一片私密区域.近日,最新升级推出的QQ空间Android3.3版新增空间权限以及相册权限的设置,让用户随时设置权限 ...

  8. Android QQ空间浏览图片动画特效的实现(※)

    1 http://blog.csdn.net/yangblocker/article/details/12680247 2 photoview 3 nineoldandroid

  9. 智能家居项目(三)之框架设计及框架代码文件工程建立

    目录 一.智能家居项目框架设计草图 二.框架代码文件工程建立 三.添加声音识别模块的串口读取功能 一.智能家居项目框架设计草图 代码思路讲解: 1.一个指令工厂,一个控制工厂,实际上就是通过链表链起来 ...

最新文章

  1. Android开发:Handler的简单使用(一)
  2. Java依赖注入选项
  3. PHP无法执行MySQL语句,解决PHP执行批量MySQL语句的问题
  4. [Learn AF3]第七章 App framework组件之Popup
  5. SPSS基本数据处理(二)
  6. 如何使用百度地图实现当前定位
  7. zookeeper学习一-ZK简介
  8. 企业邮箱账号,如何在foxmail上创建
  9. linux怎么查看hwaddr_怎么查询linux centos mac地址
  10. Vuepress-theme-reco 构建博客上传GitHub可以访问,无法正常显示。
  11. 解决mysql sum求和返回null问题或IFNULL应用
  12. 点击屏幕其他地方让edittext失去焦点 的实现
  13. A律十三折线法G711编解码介绍
  14. U3D: 先激活、在操作,才能起作用
  15. leetcode-4.11[1276. 不浪费原料的汉堡制作方案、237. 删除链表中的节点、657. 机器人能否返回原点](python解法)
  16. 哈工大软件过程与工具复习总结
  17. 5个技巧打造令人印象深刻的LOGO
  18. 香港的房价真的那么贵吗?用数据挖掘真相!
  19. iot 开源平台thingsboard使用总结
  20. Java码农坎坷之路~单例抽象类接口

热门文章

  1. C#读取Excel表格去掉空行
  2. 惠普服务器安装usb系统安装win7系统,惠普ProOne 600装win7系统教程(含BIOS设置USB驱动)...
  3. java JPanel设置边框和标题
  4. JPA 链表查询,子查询操作
  5. 手把手教学京东api接口全部操作过程
  6. 微信小程序主体如何变更?小程序迁移流程详解
  7. python积木编程软件_童心制物慧编程全新 Python 编辑器正式上线
  8. 【不就是java设计模式吗】设计模式七大原则,用代码对比方式,化抽象为具体,实打实的教会你
  9. 你究竟有多了解开源?InfoQ《中国开源发展研究分析 2022 》发布
  10. agc012E Camel and Oases(状压dp+思路题)