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 ...
随机推荐
- xmlDoc.SelectNodes用法(获取不到节点时注意事项)
注:以下举例仅针对xml自定义了命名空间的情况,如果是其他情况,请参照他人博客~ using System;using System.Collections.Generic;using System. ...
- 第十六篇、MBprogressHUD的使用和获取当前的控制器
简介: 在开发应用的时候,为了更好的增加用户的体验,常常在客户端向服务端请求数据的时候,在适当的地方加上非模态HUD,让用户可以可以知道当前的进度,稍作等待. MBProgressHUD 第三方框架G ...
- C#break、continue、return、goto
1.break break语句会使运行的程序立即退出包含在其中的最内层循环(结束此次循环且结束该循环控制体)或者switch语句 ; ; j < ; j++) { i++; )break; Co ...
- SpringInAction读书笔记--第2章装配Bean
实现一个业务需要多个组件相互协作,创建组件之间关联关系的传统方法通常会导致结构复杂的代码,这些代码很难被复用和单元测试.在Spring中,对象不需要自己寻找或创建与其所关联的其它对象,Spring容器 ...
- shell环境
1 引言 一个进程运行在shell环境中,理解进程运行的环境是十分重要的.环境影响着进程的行为,利用环境提供的便利,可以极大地提高开发效率.本节深入讨论shell中与进程有关的环境问题,包括命令行参数 ...
- Spring.Net AOP实例
Spring.Net和Log4net.NUnit.NHibernate一样,也是先从Java中流行开来,然后移植到了.NET当中,形成了.NET版的Spring框架.其官方网站为:http://www ...
- ContextMenuOpening 事件
ContextMenuOpening事件,不能在将要触发的目标ContextMenu中触发,只能包含 这个ContextMenu的父控件中触发该事件. 在ListView中,希望控制右键弹出菜单时,可 ...
- Visual Assist安装、破解方法
1.从各种渠道下载Visual Assist安装程序及破解补丁. 2.在路径(Win7):C:\Users\UserName\AppData\Local\Microsoft\VisualStudio\ ...
- div+css实现的左右两个等高div
工作当中我们经常会有这样的需求,尤其是在一些内容页面或者网站后台管理页面:左边的div的高度会随着右边的div的内容的增加儿增加,右边div的高度也会随着左边div的内容的增加而增加,也就是左右两侧两 ...
- normalize.css介绍
Normalize.css 只是一个很小的CSS文件,但它在默认的HTML元素样式上提供了跨浏览器的高度一致性.相比于传统的CSS reset,Normalize.css是一种现代的.为HTML5准备 ...