Android在layout xml中使用include
Android include与merge标签使用详解 - shuqiaoniu的博客 - 博客频道 - CSDN.NET
http://blog.csdn.net/shuqiaoniu/article/details/46013771
在Android的layout样式定义中,可以使用xml文件方便的实现,有时候为了模块的复用,使用include标签可以达到此目的。例如:
<include layout="@layout/otherlayout"></div>
Android开发的官方网站的说明在这里。
其中,有提到:
Similarly, you can override all the layout parameters. This means that any android:layout_* attribute can be used with the
<include>tag.意思是任何android:layout_*属性都可以应用在标签中。
如果使用如下代码:
<Relativelayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Textview
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/somestring"
android:id="@+id/top" />
<include layout="@layout/otherlayout"
android:layout_below="@id/top" />
</Relativelayout >
发现include的otherlayout,并没有在如我们预期的在id/top这个TextView下面,而是忽略了android:layout_below属性。经过Google发现,很多人遇到类似的问题。
有解决方法是在include的外面再包一层LinearLayout,如下:
<Linearlayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/top" >
<include layout="@layout/otherlayout">
</Linearlayout >
在Statckoverflow上找到了更好的解决方法: 解答道:必须同时重载layoutwidth和layoutheight熟悉,其他的layout_*属性才会起作用,否这都会被忽略掉。上面的例子应该写成这样:
<include layout="@layout/otherlayout">
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/top" />
另外,关于xml的复用,还可以使用merge标签,merge标签主要是用来优化显示的,减少View树的层级,可以参考这里:https://developer.android.com/resources/articles/layout-tricks-merge.html, 翻译版在这里:http://apps.hi.baidu.com/share/detail/20871363
Android在layout xml中使用include
http://blog.csdn.net/race604/article/details/7564088
Android里merge和include标签的使用 - xiabo852105的专栏 - 博客频道 - CSDN.NET
http://blog.csdn.net/xiabo851205/article/details/7841937
Android include与merge标签使用详解 - shuqiaoniu的博客 - 博客频道 - CSDN.NET
http://blog.csdn.net/shuqiaoniu/article/details/46013771
Android在layout xml中使用include的更多相关文章
- Android在layout xml中使用include完成静态加载
Android在layout xml中使用include完成静态加载 include静态加载:不仅可以加载布局,还可以加载控件(控件标签名要在最外层)include标签中有个layout属性就是专门用 ...
- Android在layout xml中使用include[转]
在Android的layout样式定义中,可以使用xml文件方便的实现,有时候为了模块的复用,使用include标签可以达到此目的.例如: <include layout="@layo ...
- Android在layout xml中使用ViewStub完成动态加载
Android在layout xml中使用ViewStub完成动态加载 一.Layout XML文件常见的两种模块加载方式 1.静态加载:被加载的模块和其它模块加载的时间一样. <include ...
- android xml中使用include标签
在一个项目中,我们可能会在xml中局部用到相同的布局,如果每次都在xml中重写这些布局,代码显得很冗余.重复的复制黏贴也很烦恼,所以,我们把这些相同的局部布局写成一个单独的xml模块,需要用到这些布局 ...
- Android——inflate 将一个xml中定义的布局找出来
通俗的说,inflate就相当于将一个xml中定义的布局找出来. 因为在一个Activity里如果直接用findViewById()的话,对应的是setConentView()的那个layout里的组 ...
- 【原创】Android多个xml文件的使用
Android中经常会使用多个xml文件,但在Mainactivity中使用的setContentView(R.layout.main)只加载main.xml文件,其他xml文件不加载进当前视图,当我 ...
- Android XML中引用自定义内部类view的四个why
今天碰到了在XML中应用以内部类形式定义的自定义view,结果遇到了一些坑.虽然通过看了一些前辈写的文章解决了这个问题,但是我看到的几篇都没有完整说清楚why,于是决定做这个总结. 使用自定义内部类v ...
- 【转】在Android布局中使用include和merge标签
内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...
- Android自己定义控件而且使其能够在xml中自己定义属性
为什么要自己定义View android开发中自己定义View的优点是显而易见的.比方说以下的这个顶部导航,它被设计出如今应用的每一个界面,但每次的内容却不尽同样.我们不能在每一个layout资源中都 ...
随机推荐
- Android SD卡存储
原创文章,转载请注明出处:http://www.cnblogs.com/baipengzhan/p/Android_SDcard_store.html 一 概念 SD卡存储空间比较大,当需要存取较大的 ...
- History lives on in this distinguished Polish city 2017/1/4
原文 History lives on in this distinguished Polish city Though it may be ancient. KraKow, Poland, is a ...
- 父子页面之间元素相互操作(iframe子页面)
js/jquery获取iframe子页面中元素的方法: 一.使用window.frames["iframe的ID"]获取元素 window.onload = function() ...
- 逆向工程学习第一天--一个VC6编译的小程序
今天开始研究二进制了,开个文记录一下.下面是一个小程序的OD反汇编代码,自己尝试加了注释,本人逆向零基础,属于摸着石头过河的类型,有理解错误的地方,希望大牛不吝赐教. 源代码: #include< ...
- HotSpot JVM常用参数设置
转自:https://www.zybuluo.com/jewes/note/57352 选项的分类 Hotspot JVM提供以下三大类选项: 1. 标准选项:这类选项的功能是很稳定的,在后续版本中也 ...
- 编译安装 Centos 7 x64 + tengine.2.0.3 (实测+笔记)
系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:CentOS Linux release 7.0.1406 安装步骤: 1.系统环境 1.1 更新系统 [root@c ...
- 原生javascript 实现 animate
原生javascript 实现 animate //animate function getstyle(obj,name){ if(obj.currentStyle){ return obj.curr ...
- Visual SVN 5.01 Po jie 笔记
最近搞项目要与几个同事一起coding,鉴于代码的合并和提交的问题,所以要搞个版本管理.由于是私有的项目,所以退git 求SVN了.装了乌龟和Visual SVN,才发现Visual SVN的客户端不 ...
- java创建文件和目录
java创建文件和目录 2013-09-04 12:56 99933人阅读 评论(7) 收藏 举报 分类: JAVA基础(10) 版权声明:本文为博主原创文章,未经博主允许不得转载. 创建文件和目 ...
- phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...