`
从此醉
  • 浏览: 1039108 次
  • 性别: Icon_minigender_1
  • 来自: US
社区版块
存档分类
最新评论

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

 
阅读更多

大家好,今天是元旦节了,祝大家节日快乐!今天给大家分享的是Apad Qzone的UI框架,我们首先看下交互图如下:

图1:交互效果图.

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

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

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

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

图2:程序代码结构图:

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

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

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

package com.tutor.frame;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

public class QZRightWindowContainer extends FrameLayout {

	public QZRightWindowContainer(Context context){
		super(context);
	}
	public QZRightWindowContainer(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

}


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

package com.tutor.frame;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.TextView;

public abstract class QZRightWindowBase extends FrameLayout {

	public TextView mContentTextView;
	
	private LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
			LayoutParams.FILL_PARENT);
		
	public QZRightWindowBase(Context context){
		super(context);
		setupViews();
	}
	
	public QZRightWindowBase(Context context, AttributeSet attrs) {
		super(context, attrs);
		setupViews();
	}
	
	private void setupViews(){
		mContentTextView = new TextView(getContext());
		mContentTextView.setLayoutParams(params);
	}
	
	//做些事为了扩展举例而已
	public abstract void dosomething();
	//做些事2
	public abstract void dosomething2();

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

package com.tutor.frame;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;

public class QZRightWindow1 extends QZRightWindowBase{

	public QZRightWindow1(Context context){
		super(context);
		setupViews();
	}
	public QZRightWindow1(Context context, AttributeSet attrs) {
		super(context, attrs);
		setupViews();
	}
	
	private void setupViews(){
		mContentTextView.setText("好友动态");
		mContentTextView.setBackgroundColor(Color.RED);
		addView(mContentTextView);
	}

	@Override
	public void dosomething() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dosomething2() {
		// TODO Auto-generated method stub
		
	}

}

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

package com.tutor.frame;

import java.util.HashMap;
import java.util.Iterator;

import android.view.View;




public class QZRightWindowManager {

	 /**
     * 好友动态面板的KEY
     */
    public static final int FRIEND_TRENDS_WINDOW = 0;
    
	 /**
     * 个人中心面板的KEY
     */
    public static final int HOME_PAGE_WINDOW = 1;
    
	 /**
     * 好友关系链面板的KEY
     */
    public static final int FRIEND_LIST_WINDOW = 2;
    
	 /**
     * 应用中心面板的KEY
     */
    public static final int APP_CENTER_WINDOW = 3;
    
    
    private HashMap<Integer, QZRightWindowBase> mHashMap;
    
	private QZRightWindowContainer mContainer;
	
	
	public QZRightWindowManager(){
		mHashMap = new HashMap<Integer, QZRightWindowBase>(); 
	}
	
	public void setmContainer(QZRightWindowContainer container) {
		this.mContainer = container;
	}
	
	public void showRightWindow(int num,QZRightWindowBase mQzRightWindowBase){
		if(!mHashMap.containsKey(num)){
			mHashMap.put(num, mQzRightWindowBase);
			if(!(mQzRightWindowBase instanceof QZRightWindow1)){
				mContainer.addView(mQzRightWindowBase);
			}
		}
		
		for (Iterator iter = mHashMap.keySet().iterator(); iter.hasNext();) {
			Object key = iter.next();
			QZRightWindowBase qzb = mHashMap.get(key);
			qzb.setVisibility(View.INVISIBLE);
		}
		
		mQzRightWindowBase.setVisibility(View.VISIBLE);
	}
	
}

主程序QzoneFrameDemoActivity代码如下:

package com.tutor.framedemo;

import com.tutor.frame.QZLeftNavBar;
import com.tutor.frame.QZRightWindow1;
import com.tutor.frame.QZRightWindow2;
import com.tutor.frame.QZRightWindow3;
import com.tutor.frame.QZRightWindow4;
import com.tutor.frame.QZRightWindowBase;
import com.tutor.frame.QZRightWindowContainer;
import com.tutor.frame.QZRightWindowManager;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class QzoneFrameDemoActivity extends Activity implements OnClickListener{
    
	private QZRightWindow1 mQzRightWindow1;
	
	private QZRightWindow2 mQzRightWindow2;
	
	private QZRightWindow3 mQzRightWindow3;
	
	private QZRightWindow4 mQzRightWindow4;
	
	private QZLeftNavBar mQzLeftNavBar;
	
	private QZRightWindowContainer mQzRightWindowContainer;
	
	private QZRightWindowManager mQzRightWindowManager;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        setupViews();
    }
    
    private void setupViews(){
    	mQzRightWindowManager = new QZRightWindowManager();
    	
    	mQzLeftNavBar = (QZLeftNavBar)findViewById(R.id.navbar);
    	
    	mQzLeftNavBar.findViewById(R.id.rw1).setOnClickListener(this);
    	mQzLeftNavBar.findViewById(R.id.rw2).setOnClickListener(this);
    	mQzLeftNavBar.findViewById(R.id.rw3).setOnClickListener(this);
    	mQzLeftNavBar.findViewById(R.id.rw4).setOnClickListener(this);
    	
    	mQzRightWindow1 = (QZRightWindow1)findViewById(R.id.qzrw1);
    	
    	mQzRightWindowContainer = (QZRightWindowContainer)findViewById(R.id.container);
    	mQzRightWindowManager.setmContainer(mQzRightWindowContainer);
    }

    private void showRightWindow(int num,QZRightWindowBase mQzRightWindowBase){
    	mQzRightWindowManager.showRightWindow(num, mQzRightWindowBase);
    }
    
	@Override
	public void onClick(View v) {		
		int id = v.getId();
		switch (id) {
		case R.id.rw1:
			showRightWindow(QZRightWindowManager.FRIEND_TRENDS_WINDOW, mQzRightWindow1);
			break;
		case R.id.rw2:
			if(mQzRightWindow2 == null){
				mQzRightWindow2 = new QZRightWindow2(this);
			}
			showRightWindow(QZRightWindowManager.HOME_PAGE_WINDOW, mQzRightWindow2);
			break;
		case R.id.rw3:
			if(mQzRightWindow3 == null){
				mQzRightWindow3 = new QZRightWindow3(this);
			}
			showRightWindow(QZRightWindowManager.FRIEND_LIST_WINDOW, mQzRightWindow3);
			break;
		case R.id.rw4:
			if(mQzRightWindow4 == null){
				mQzRightWindow4 = new QZRightWindow4(this);
			}
			showRightWindow(QZRightWindowManager.APP_CENTER_WINDOW, mQzRightWindow4);
			break;
		default:
			break;
		}
	}
}

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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <com.tutor.frame.QZLeftNavBar
        android:id="@+id/navbar"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"/>

    <com.tutor.frame.QZRightWindowContainer
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
     >
     	<com.tutor.frame.QZRightWindow1
     	     android:id="@+id/qzrw1"
     	     android:layout_width="fill_parent"
       		 android:layout_height="fill_parent"
     	  />
     </com.tutor.frame.QZRightWindowContainer>
</LinearLayout>

运行效果如下:

效果1

效果2.

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

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

源代码点击进入==>

分享到:
评论

相关推荐

    MATLAB算法插值与拟合代码

    MATLAB算法插值与拟合代码提取方式是百度网盘分享地址

    基于二级计算机系统建立无取向硅钢轧制模型的研究

    随着计算机的发展及轧制自动化程度的提高,计算机控制系统在带钢热连轧生产线 中发挥着越来越重要的作用。硅钢作为钢中的艺术品,对轧制精度要求极高,传统的计 算机控制系统轧制模型并不能适应硅钢高精度轧制的生产要求,因此,开发设计精确的 轧制模型显得尤为重要。 本文以包钢CSP热连轧计算机控制系统为研究对象,针对原有轧制模型生产硅钢无 法达到成品厚度要求精度的问题,以新品种硅钢50SW800为研究对象,开发了适应性 较好的厚度精度控制轧制力模型与轧制力自学习模型,实际运行良好。主要工作及结论 如下: 通过分析大量硅钢轧制的重要工艺参数的变化规律,剔除温度、张力、摩擦力等影 响参数,主要针对带钢的变形抗力进行研究,采用微单元的塑性变形方程式,进行硅钢 变形抗力参数的计算,并利用在轧制时材料化学元素、变形率、温度、实际轧制压力、 理论轧制压力等数据通过多元线性回归得出新的轧制压力修正系数,最终成功构建了轧 制力模型,最终将该轧制力模型用于硅钢的轧制力设定预计算,首坯轧制偏差降低60%。

    uAI - AI Assistant 1.3.7人工智能助手Unity插件unitypackage项目源码C#

    uAI - AI Assistant 1.3.7人工智能助手Unity插件unitypackage项目源码C# 支持Unity版本2020.3.45或更高 uAI Assistant 是 Unity 的扩展,提供了一套强大的工具,由 OpenAI 最新的 GPT-4 Turbo 提供支持,具有 128k 上下文窗口、3.5 AI 模型以及 Dall-E 2 和 Dall-E 3。 uAI Assistant 中包含的 DemoScene 使用 Unity 包管理器中的 TextMeshPro 包作为 UI 文本。确保在导入此包之前导入它。 还要导入“TMP Essential Resources”,因为 DemoScene 使用“LiberationSans.ttf”字体。有关说明,请参阅文档。 uAI 助手? uAI Assistant 是 Unity 游戏引擎的强大扩展,它使用 GPT AI 帮助游戏开发人员轻松创建专业代码和引人入胜的游戏内容。 您需要 OpenAI 密钥才能使用 uAI Assistant!请阅读我们的文档以获取更多说明。 让你的纹理变得无缝 使用 AI 创建

    2024年全球液化天然气船用发电机组行业总体规模、主要企业国内外市场占有率及排名.docx

    2024年全球液化天然气船用发电机组行业总体规模、主要企业国内外市场占有率及排名

    AX3_model_extras-1.5.3-py3-none-any.whl.zip

    AX3_model_extras-1.5.3-py3-none-any.whl.zip

    人工智能+​NLP(Natural Language Processing)技术+技术原理图

    人工智能+​NLP(Natural Language Processing)技术+技术原理图 自然语言处理(NLP)是人工智能(AI)最热门的领域之一,这要归功于一些应用程序,如撰写连贯文章的文本生成器、欺骗人们认为自己有感知能力的聊天机器人,以及生成任何你能描述的真实图像的文本到图像程序。近年来,计算机理解人类语言、编程语言,甚至类似于语言的生物和化学序列,如DNA和蛋白质结构的能力发生了革命性的变化。最新的人工智能模型正在解锁这些领域,以分析输入文本的含义,并生成有意义、有表达力的输出。

    BCS-Service

    .Net core 6

    AVMSpeechMath-0.0.4-py3-none-any.whl.zip

    AVMSpeechMath-0.0.4-py3-none-any.whl.zip

    小学Scratch游戏化教学的实践研究-以泰州市Y小学为例

    随着智能教育时代的到来,计算机教育击彴祀勺中小学生必不可少的课程。我国陆续出台的文件,均指向鼓励在基础教育阶段开展编程课程。Scratch软件作为一种新型编程工具,以其简单易学、趣味性强等特点深受广大青少年丿谨i喜爱。但在日常教学中发现,传统讲授式教学方式不能长期维待学生学习兴趣,妇比以往学习效果大打折扣。2022年出版的《义务 教育信息科技课程标准》中明确指出,要求教育工作者创新教学方式,创设真实情境以提高 学生学习参与度。游戏化教学这种创新型教学方式, 在与各学科良好的结合效果下,也逐渐进入信息教育者的视野。因此本研究旨在将游戏化元素融入Scratch课堂,探究 Scratch游戏化教学设计一般流程在行动中不断峦进, 以期得到有效实施的策略和建议。 通过三轮行动研究,验证了小学Scratch游戏化教学的一般流程。同时总结出游戏化教学 应用策略,包括在游戏化教学设计时需要合理制定游戏规则,以控制课堂纪律和给予学生适当激励;明确小组分工,学生各司其职,在组内合作和组间竞争中培养学生合作精神;采用多元化评价方式,综合运用纸笔测试和个性创作等方法自评与他评相结合的方式,增强学 生自主学习能

    VB+access智能排课系统(源代码+可执行程序+4万字LW+答辩PPT)

    VB+Access智能排课系统是一个综合性的软件开发项目,旨在利用Visual Basic(VB)和Access数据库技术,为教育机构提供一个高效、智能的排课管理工具。 该系统通过深入分析教育机构的排课需求,设计了合理的数据库结构,包括教师信息、学生信息、课程安排等关键数据表。基于这些数据结构,系统实现了自动排课、手动调整、课程查询等功能,满足了教育机构对于排课工作的多样化需求。 在开发过程中,我们注重用户体验,设计了简洁明了的界面和流畅的操作流程。用户可以通过系统快速录入课程信息、教师资源和学生名单,系统则能够自动根据预设规则进行排课,大大减轻了人工排课的负担。同时,系统还提供了手动调整功能,方便用户对自动排课结果进行微调和优化。 此外,我们还为该系统撰写了详尽的4万字论文,深入探讨了智能排课系统的设计理念、实现方法以及在教育领域的应用前景。同时,为了方便答辩,我们还制作了答辩PPT,清晰展示了系统的功能特点、技术实现和应用效果。

    2024-2030全球及中国液化天然气船用发电机组行业研究及十五五规划分析报告.docx

    2024-2030全球及中国液化天然气船用发电机组行业研究及十五五规划分析报告

    Python安装文件(MAC苹果系统)

    0.Python安装教程-Mac、pycharm-community-2022.2.1、python-3.10.7-macos11

    Acquisition-4.11-cp37-cp37m-manylinux_2_17_aarch64.whl.zip

    Acquisition-4.11-cp37-cp37m-manylinux_2_17_aarch64.whl.zip

    算法参考资料温度控制的PID程序

    算法参考资料温度控制的PID程序提取方式是百度网盘分享地址

    AccessControl-6.0-cp311-cp311-manylinux_2_5_i686.whl.zip

    AccessControl-6.0-cp311-cp311-manylinux_2_5_i686.whl.zip

    Acquisition-4.11-cp39-cp39-manylinux_2_5_i686.whl.zip

    Acquisition-4.11-cp39-cp39-manylinux_2_5_i686.whl.zip

    AccessControl-5.3-cp36-cp36m-manylinux_2_5_i686.whl.zip

    AccessControl-5.3-cp36-cp36m-manylinux_2_5_i686.whl.zip

    AccessControl-5.5-cp39-cp39-manylinux_2_17_aarch64.whl.zip

    AccessControl-5.5-cp39-cp39-manylinux_2_17_aarch64.whl.zip

    MATLAB算法GRNN的数据预测广义回归神经网络货运量预测

    MATLAB算法GRNN的数据预测-基于广义回归神经网络货运量预测提取方式是百度网盘分享地址

    人工智能发展和应用PPT

    人工智能发展和应用PPT,资源比较新

Global site tag (gtag.js) - Google Analytics