android开发之merge结合include优化布局
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优化布局的更多相关文章
- 【Android UI】Android开发之View的几种布局方式及实践
		
引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...
 - 【转】Android开发之Bitmap的内存优化详解
		
本文来源:转载自: http://mobile.51cto.com/abased-410796.htm 在Android应用里,最耗费内存的就是图片资源.而且在Android系统中,读取位图Bitma ...
 - Android开发之多Fragment切换优化
		
问题分析 一直在简书里看别人的技术贴,今天我也来写点自己的心得!最近在写一个项目用到大量的Fragment后的总结! 我想刚刚接触安卓的同学或许会这么写: FragmentManager fragme ...
 - Android 开发之旅:深入分析布局文件&又是“Hello World!”
		
http://www.cnblogs.com/skynet/archive/2010/05/20/1740277.html 引言 上篇可以说是一个分水岭,它标志着我们从Android应用程序理论进入实 ...
 - Android开发之Java必备基础
		
Android开发之Java必备基础 Java类型系统 Java语言基础数据类型有两种:对象和基本类型(Primitives).Java通过强制使用静态类型来确保类型安全,要求每个变量在使用之前必须先 ...
 - Android开发之旅3:android架构
		
引言 通过前面两篇: Android 开发之旅:环境搭建及HelloWorld Android 开发之旅:HelloWorld项目的目录结构 我们对android有了个大致的了解,知道如何搭建andr ...
 - Android开发之旅: Intents和Intent Filters(理论部分)
		
引言 大部分移动设备平台上的应用程序都运行在他们自己的沙盒中.他们彼此之间互相隔离,并且严格限制应用程序与硬件和原始组件之间的交互. 我们知道交流是多么的重要,作为一个孤岛没有交流的东西,一定毫无意义 ...
 - Android开发之ViewPager+ActionBar+Fragment实现响应式可滑动Tab
		
今天我们要实现的这个效果呢,在Android的应用中十分地常见,我们可以看到下面两张图,无论是系统内置的联系人应用,还是AnyView的阅读器应用,我们总能找到这样的影子,当我们滑动屏幕时,Tab可 ...
 - Android开发之PopupWindow
		
/* * Android开发之PopupWindow * * Created on: 2011-8-8 * Author: blueeagle * Email: liujiaxiang@g ...
 
随机推荐
- 【HDU 4372】 Count the Buildings (第一类斯特林数)
			
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
 - [wikioi]乌龟棋
			
http://wikioi.com/problem/1068/ 多重背包.边界f[0,0,0,0]=a[1](初始时没有用任何卡片,获得棋盘第一格的分数)DP方程:f[i,j,k,l]=max(f[i ...
 - 解决wordpress上传的文件尺寸超过 php.ini 中定义的 upload_max_filesize 值。
			
上传的文件尺寸超过 php.ini 中定义的 upload_max_filesize 值. 解决方法:修改/etc/php5/apache2/php.ini文件中的 post_max_size = 6 ...
 - android 对象传输及parcel机制
			
在开发中不少要用到Activity直接传输对象,下面我们来看看,其实跟java里面差不多 自定义对象的传递:通过intent传递自定义对象的方法有两个 第一是实现Serialization接口: ...
 - Earth to developers: Grow up!
			
这是篇老外写的文章,主题是针对网络上的一些宗教式的争论,作者叙述了他自己的一些观点.主要从以下6点做了陈述.为了表达的精确性,就直接用英文. 1. Reject dogmatic thinking a ...
 - default 关键字泛型代码中的默认关键字(C# 编程指南)
			
在泛型类和泛型方法中产生的一个问题是,在预先未知以下情况时,如何将默认值分配给参数化类型 T: T 是引用类型还是值类型. 如果 T 为值类型,则它是数值还是结构. 给定参数化类型 T 的一个变量 t ...
 - 一起啃PRML - 1.2.3 Bayesian probabilities 贝叶斯概率
			
一起啃PRML - 1.2.3 Bayesian probabilities 贝叶斯概率 @copyright 转载请注明出处 http://www.cnblogs.com/chxer/ 这一节简单讲 ...
 - 64位windows7 上安装32位oracle 10g 的方法
			
操作系统: windows7 中文旗舰版 oracle安装版本: 10.2.0.1 中文版,升级补丁至 10.2.0.3 下面说正题首先,我们要解除oracle安装的windows版本检测1.编辑安装 ...
 - 进军es6(2)---解构赋值
			
本该两周之前就该总结的,但最近一直在忙校招实习的事,耽误了很久.目前依然在等待阿里HR面后的结果中...但愿好事多磨!在阿里的某轮面试中面试官问到了es6的掌握情况,说明es6真的是大势所趋,我们更需 ...
 - KEIL、uVision、RealView、MDK、KEIL C51区别比较
			
KEIL uVision,KEIL MDK,KEIL For ARM,RealView MDK,KEIL C51,KEIL C166,KEIL C251 从接触MCS-51单片机开始,我们就知道有一个 ...