android中include 的使用讲解
include的作用就是重复使用同一段代码,提高代码的重用性。具体说就是,通过include 在 某布局 a.xml 中引用 B.xml布局文件,这个b.xml可同时被多个布局同时使用,所以达到了同一段代码重用的效果。
在使用include 的时候,通常需要在其外层包裹一个布局,如下:
<LinearLayout
android:id="@+id/mLinearLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"> <include layout="@layout/include1" /> </LinearLayout>
这个布局是用来设置 include 的位置、宽高等属性的。
当然还有一种方式就是可以直接在include 里面设置它的这些属性,这里不举例了。仅说一下在include 外面包裹的用法。
下面用一小段例子来说明:
include1.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="这是第一个布局文件 !"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
include2.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="这是第一个布局文件 "
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
用 include 引用以上两个布局文件(include1.xml 和 include2.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <LinearLayout
android:id="@+id/mLinearLayout3"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center" > <include layout="@layout/include1"/>
</LinearLayout> <LinearLayout
android:id="@+id/mLinearLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"> <include layout="@layout/include2" />
</LinearLayout> </LinearLayout>
通过LinearLayout的包裹对其设置在当前界面的位置,如include1 设置在布局中间,include2 设置在布局底部。
android中include 的使用讲解的更多相关文章
- android中include标签使用详解
android中include标签是为了便于控件的覆用的一个很好解决方案. 但是也有一些需要注意的地方,下面是本人在项目中碰到过的一个问题,做此记录,便于以后查看. include标签用法. ...
- android中include
android中include. include标签用法. 1.新建一个xml文件,命名 head.xml head.xml文件内容如下: <?xml version="1.0&quo ...
- Android中include标签的使用
在Android的开发中,我们知道布局文件可以让我们很方便的对各个UI控件进行位置安排跟属性设置,而在程序中可以直接取得控件并赋予对应操作功能.但是,如果是一个复杂的界面设计,我们把所有布局都放在一个 ...
- 【Android 界面效果25】android中include标签的使用
在一个项目中我们可能会需要用到相同的布局设计,如果都写在一个xml文件中,代码显得很冗余,并且可读性也很差,所以我们可以把相同布局的代码单独写成一个模块,然后用到的时候可以通过<include ...
- Android中include标签的使用(打开引用布局,隐藏当前布局)
在开发app的时候,有时候一个布局会反复用到,可以把反复用到的布局单独写一个xml文件,什么时候用到就用includ标签引入xml 下面是我写的反复用到的一个xml,里面有2个button,一个Tex ...
- android中Adapter适配器的讲解
Adapter(适配器的讲解) 适配器就我自己来看,我觉得这是一个非常重要的知识点,Adapter是用来帮助填出数据的中间桥梁,简单点说吧:将各种数据以合适的形式显示在View中给用户看.Adapte ...
- 我的Android进阶之旅------>Android中Dialog系统样式讲解
今天在维护公司的一个APP的时候,有如下场景. 弹出一个AlertDialog的时候,在系统语言是中文的时候,如下所示: 弹出一个AlertDialog的时候,在系统语言是English的时候,如下所 ...
- 关于android中postDelayed方法的讲解
这是一种可以创建多线程消息的函数使用方法:1,首先创建一个Handler对象 Handler handler=new Handler(); 2,然后创建一个Runnable对象Runnable run ...
- 关于 android 中 postDelayed方法的讲解 (转载)
转自:http://blog.csdn.net/xiabo851205/article/details/7991529 这是一种可以创建多线程消息的函数 使用方法: 1,首先创建一个Handler对象 ...
随机推荐
- 纸上谈兵:排序算法简介及C实现
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 排序算法(Sorting Algorithm)是计算机算法的一个组成部分. 排序的 ...
- 学习java第7天
关于继承还需要留意的是,子类中的所有构造方法都默认访问父类的无参构造,注意是无参,而且是必须的,如果父类没有无参子类就会报错.如果你不想给父类无参构造,那么在子类中加上super(),显式的调用有参构 ...
- 炫酷的时钟--canvas初体验
先啥也不说:来张效果图 我是根据:http://www.imooc.com/learn/133 这里的课程进行学习的.大大的感谢liuyubobobo老师的深入浅出的讲解!! 我在这里仅仅提供我自己的 ...
- sql按字段值进行统计
用group by 如有个student表里有性别sex来统计 select sex,count(*) from student group by sex;
- [简单]docx4j常用方法小结
http://53873039oycg.iteye.com/blog/2194479?utm_source=tuicool&utm_medium=referral —————————————— ...
- AX2012 DMF数据导入的问题
由于AX2012的数据结构比较复杂,通过Excel直接导入表的方式很多数据已经难以导入,比如物料信息,2009只需要导入InventTable,InventTableModule和InventItem ...
- Jquery实现简单到计时功能(setTimeout,setInterval)
要实现一个标签或者按钮进行5秒到计时,非常简单,直接上代码: 倒计时:<span id="timeSpan1" style="color:red;font-size ...
- proc文件系统在内核中的表现
当Linux内核启动起来之后,我们可以通过proc虚拟文件系统来查看内的中的一些动态信息. 例如:可以 cat /proc/misc 来查看系统中装载的所有misc类设备 cat /proc/d ...
- Linux内核分析第三周学习总结:构造一个简单的Linux系统MenuOS
韩玉琪 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.Linux内 ...
- android笔记:Notification通知的使用
通知(Notification),当某个应用程序希望向用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现. 发出一条通知后,手机最上方的状态栏中会显示一个通知的图标,下拉状态栏后 ...