merge结合include优化android布局,效果不知道,个人感觉使用上也有很大的局限,不过还是了解一下,记录下来。

布局文件都要有根节点,但android中的布局嵌套过多会造成性能问题,于是在使用include嵌套的时候我们可以使用merge作为根节点,这样可以减少布局嵌套,提高显示速率。

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="张三" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="李四" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="王五" /> </merge>

上面的界面在显示的时候会自动嵌套到下面的文件中。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.viewstub.MainActivity" > <include layout="@layout/top"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="显示/隐藏" /> <ViewStub
android:id="@+id/vs"
android:layout_margin="50dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/inflated_id"
android:layout="@layout/view_stub_layout" /> </LinearLayout>

我为什么说这个局限性比较大呢?因为merge中的空间显示的使用会采用主布局文件的方式来显示,比如我这里主布局是linearlayout且是水平排列,那么merge中的元素显示出来之后也是水平排列,可是我如果想让merge中的元素垂直排列呢?抱歉,做不到。

版权声明:本文为博主原创文章,未经博主允许不得转载。若有错误地方,还望批评指正,不胜感激。

android开发之merge结合include优化布局的更多相关文章

  1. 【Android UI】Android开发之View的几种布局方式及实践

    引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...

  2. 【转】Android开发之Bitmap的内存优化详解

    本文来源:转载自: http://mobile.51cto.com/abased-410796.htm 在Android应用里,最耗费内存的就是图片资源.而且在Android系统中,读取位图Bitma ...

  3. Android开发之多Fragment切换优化

    问题分析 一直在简书里看别人的技术贴,今天我也来写点自己的心得!最近在写一个项目用到大量的Fragment后的总结! 我想刚刚接触安卓的同学或许会这么写: FragmentManager fragme ...

  4. Android 开发之旅:深入分析布局文件&又是“Hello World!”

    http://www.cnblogs.com/skynet/archive/2010/05/20/1740277.html 引言 上篇可以说是一个分水岭,它标志着我们从Android应用程序理论进入实 ...

  5. Android开发之Java必备基础

    Android开发之Java必备基础 Java类型系统 Java语言基础数据类型有两种:对象和基本类型(Primitives).Java通过强制使用静态类型来确保类型安全,要求每个变量在使用之前必须先 ...

  6. Android开发之旅3:android架构

    引言 通过前面两篇: Android 开发之旅:环境搭建及HelloWorld Android 开发之旅:HelloWorld项目的目录结构 我们对android有了个大致的了解,知道如何搭建andr ...

  7. Android开发之旅: Intents和Intent Filters(理论部分)

    引言 大部分移动设备平台上的应用程序都运行在他们自己的沙盒中.他们彼此之间互相隔离,并且严格限制应用程序与硬件和原始组件之间的交互. 我们知道交流是多么的重要,作为一个孤岛没有交流的东西,一定毫无意义 ...

  8. Android开发之ViewPager+ActionBar+Fragment实现响应式可滑动Tab

     今天我们要实现的这个效果呢,在Android的应用中十分地常见,我们可以看到下面两张图,无论是系统内置的联系人应用,还是AnyView的阅读器应用,我们总能找到这样的影子,当我们滑动屏幕时,Tab可 ...

  9. Android开发之PopupWindow

      /* *  Android开发之PopupWindow * *  Created on: 2011-8-8 *  Author: blueeagle *  Email: liujiaxiang@g ...

随机推荐

  1. ubuntu 64bit “arm-linux-gcc: No such file or directory”问题的解决方法

    安装lsb-core sudo apt-get install lsb-core

  2. ubuntu 10.04 安装qt 5.0.2

    转自ubuntu 10.04 安装qt 5.0.2 从qt project网站下载下来最新的qt5.0.2套件,发现是个.run文件,添加x属性,然后直接sudo ./****.run, 提示  /l ...

  3. 利用if else 求房贷

    static void Main(string[] args)        {            while (true)     //主要就是公式的运用和if else 的嵌套         ...

  4. 编程实现改变win7主题

    一  : 解析问题 1. Windows 7 主题在:%windir%\Resources\Themes  : 2: 我们通过shell 命令  (这个是msdn中提到的) rundll32.exe ...

  5. xcode5.1 armv7 armv7s arm64 类型, 区分, 概念等

    官方: https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/In ...

  6. Apache.NMS.Stomp 下载

    最近项目中有用到ActiveMQ, MQ服务器61613的端口是用的STOMP协议, 原来项目中有使用MQ, 但发现缺少Apache.NMS.Stomp.dll的引用,于是上官网上找,结果发现所有的A ...

  7. 很反感Java Web 三层框架

    为什么反感,大家 看图就知道了.一层一层的框架叠加,要达到精通就要一个一个框架的去深入了解,谁有这个精力?PHP没有这么多框架,为何依然能开发大型网站呢? 不过此图的原文却在推销使用Java,原文点此 ...

  8. ListControl常用操作汇总

    本文根据本人在项目中的应用,来谈谈CListCtrl的部分用法及技巧.当初学习时,查了很多资料,零零碎碎的作了些记录,现在主要是来做个总结,方便以后查阅.主要包括以下十三点内容:基本操作.获取选中行的 ...

  9. Ubuntu----1

    1. 安装ubuntu之后,你必须要做的事情, 引自:http://itsfoss.com/things-to-do-after-installing-ubuntu-13-04/ 但是对于国人来讲,墙 ...

  10. 《A First Course in Probability》-chaper5-连续型随机变量-随机变量函数的分布

    在讨论连续型随机变量函数的分布时,我们从一般的情况中(讨论正态分布的文章中提及),能够得到简化版模型. 回忆利用分布函数和概率密度的关系求解随机变量函数分布的过程,有Y=g(x),如果g(x)是严格单 ...