Android include的使用
如果在程序中多次用到一部分相同的布局,可以先将这部分布局定义为一个单独的XML,然后在需要的地方通过<include>引入,如下:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <include
android:id="@+id/cell1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_marginTop="10dp"
layout="@layout/item" /> <include
android:id="@+id/cell2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/cell1"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/cell1"
layout="@layout/item" /> <include
android:id="@+id/cell3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/cell1"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/cell2"
layout="@layout/item" /> </RelativeLayout>
item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" > <ImageView
android:id="@+id/iv_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:clickable="true"
android:focusable="false" /> <TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_img"
android:layout_below="@+id/iv_img"
android:textColor="#a17006"
android:textSize="22dp"
android:textStyle="bold" /> </RelativeLayout>
使用Android include时需要注意的是要指定宽高属性,要不可能会出现一些意想不到的效果,比如引用了三次,而界面上只显示了一个item。
Android include的使用的更多相关文章
- android include进来的组件 调用其子元素
include标签包裹着一个可复用的布局: <include layout="@layout/footer_detail" android:id="@+id/foo ...
- Android Include标签
编程的世界有的时候很微妙,有的时候就好像是在解决一个哲学问题,Android开发的时候,所有的布局,颜色,等(其实这些都可以称之为资源,Android中的资源是指非代码部分,如图片.音频.视频.字符等 ...
- android include中的控件调用
项目中经常会有一些布局是重用的,但是如何来更好的利用这些布局中的控件 转: http://zhidao.baidu.com/link?url=GU93U8Wu31dfp7mKEx52hMJkxjFLC ...
- Android include和merge标签的使用
在Android布局文件中,某些时候使用include标签会很多的好处1,对于稍微有点复杂的布局界面,将所有布局代码都写在一个xml文件中,界面会显得很冗余,可读性很差,这时可以分开使用include ...
- Android - include属性用法
include属性用法 本文地址: http://blog.csdn.net/caroline_wendy Android的layout中, 能够使用include属性样式, 这样能够把不同的layo ...
- android include使用[转]
需要包含的xml文件,我这里就放了一个Button按钮: btn.xml: <?xml version="1.0" encoding="utf-8"?&g ...
- android include标签的使用,在RelativeLayout中使用include标签需注意!!!!!
转:http://4265337.blog.163.com/blog/static/195375820127935731114/ include和merge标记的作用主要是为了解决layout的重用问 ...
- Android在layout xml中使用include
Android include与merge标签使用详解 - shuqiaoniu的博客 - 博客频道 - CSDN.NEThttp://blog.csdn.net/shuqiaoniu/article ...
- 【Android 界面效果25】android中include标签的使用
在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include ...
随机推荐
- 【转】Open Live Writer 插件更新
一.更新内容 cnblog 页签中增加 Lua 和 Matlab 语法高亮:(SyntaxHighlight 页签中尚未添加) 增加折叠区域插件,见效果展示: 增加 bat 执行文件,直接拷贝插件所需 ...
- sql 理解视图
可以看作是定义在sqlserver上的虚拟的表,本身并不存储数据,仅仅存储一个select语句和涉及的表的引用 通过视图,客户端不再需要知道底层表结构和其之间的关系,视图提供了一个统一访问数据的接口 ...
- 【Excel VBA】金额大写转换
=IF(ROUND(A1,2)<0,"金额为负无效",IF(ROUND(A1,2)=0,"零元",IF(ROUND(A1,2)<1,"&q ...
- mac配置svn服务器
1创建svn库:mudydeMacBook-Air:~ mudy$ svnadmin create /Users/mudy/svn 2进行配置,配置我们的svn a.将svnsever.con ...
- 九度OJ 1511 从尾到头打印链表
题目地址:http://ac.jobdu.com/problem.php?pid=1511 题目描述: 输入一个链表,从尾到头打印链表每个节点的值. 输入: 每个输入文件仅包含一组测试样例. 每一组测 ...
- OpenJudge/Poj 2013 Symmetric Order
1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...
- 模板:qsort+bsearch应用
(1)qsort: 功 能: 使用快速排序例程进行排序 头文件:stdlib.h 用 法: void qsort(void *base,int nelem,int width,int (*fcmp)( ...
- 【转】mysql in语句优化
mysql会对sql语句做优化, in 后面的条件不超过一定数量仍然会使用索引.mysql 会根据索引长度和in后面条件数量判断是否使用索引. 另外,如果是in后面是子查询,则不会使用索引. 一个文章 ...
- hdu 5014 Number Sequence
为了a异或b的和最大,只需另b在不大于n的情况下按位取反即可. 这里有两个输出小技巧可以参考: 1.在用printf输出__int64时,在windows下使用格式"%I64d", ...
- ajax返回json处理
在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析. (一)以jquery异步获取的数据类型--json ...