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. 【HDU 1828】 Picture (矩阵周长并,线段树,扫描法)

    [题目] Picture Problem Description A number of rectangular posters, photographs and other pictures of ...

  2. Trace和Debug主要用法

    #region 日志记录 //System.Diagnostics.Trace.Listeners.Clear(); //System.Diagnostics.Trace.AutoFlush = tr ...

  3. IE浏览器下读取客户端上传的文件大小

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  4. 数学类杂志SCI2013-2014影响因子

    ISSN Abbreviated Journal Title Full Title Category Subcategory Country total Cites IF        2013-20 ...

  5. java基础(十六)集合(三)

    这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...

  6. HDOJ/HDU 2163 Palindromes(判断回文串~)

    Problem Description Write a program to determine whether a word is a palindrome. A palindrome is a s ...

  7. 传输层之UDP

    1.UDP的定义 跟tcp一样,我们把她定义为: 无连接的,不可靠的,用户数据报协议. 从中我们看到了:无连接和不可靠,这是它的缺点也是它的优点,因为他选择了性能,舍弃了部分安全,节约资源,速度快. ...

  8. OpenCV学习(一)

    环境:OpenCV 2.4.4 VS2010 第一个Demo,显示一张图片 #include "opencv2/highgui/highgui.hpp" int main( int ...

  9. ambari的重新安装

    ambari是什么呢? 这里我简单说一下ambari的目的,他的目的就是简化hadoop集群的安装和管理.对于安装简化到什么地步呢?只需要几个命令,在页面上配置几个参数,几百几千个节点的集群就能安装成 ...

  10. Overview of the Packages JAXP

    The SAX and DOM APIs are defined by the XML-DEV group and by the W3C, respectively. The libraries th ...