Android布局文件之 include 详细介绍
Android布局文件之 include 详细介绍
include简介
众所周知,include就是在一个布局中,导入另一个布局文件。
优势是:相同的页面只需写一次,提高了共通布局的复用性。
下面我们以标题栏为例,详细介绍其使用步骤:
include使用步骤
// 第一步:通用布局创建:title_bar
// title_bar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="50dp"android:id="@+id/bar"android:gravity="center"android:background="@android:color/holo_blue_light"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="标题栏"android:textSize="30dp"android:textColor="@android:color/white"/>
</LinearLayout>
// 第二步:在想要引入 title_bar的布局中引入
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><include layout="@layout/title_bar"/></LinearLayout>
引入后,效果图如下:
// 第三步 如果我们需要 include 两个甚至多个相同的布局时,如何区分其 ID 值呢?我们可以在 include 时重新 指定一个新的id,用来区别。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><includeandroid:id="@+id/bar1"layout="@layout/title_bar" /><includeandroid:id="@+id/bar2"layout="@layout/title_bar" />
</LinearLayout>java代码:View bar1 = findViewById(R.id.bar1);View bar2 = findViewById(R.id.bar2);TextView tv1 = (TextView) bar1.findViewById(R.id.textView);TextView tv2 = (TextView) bar2.findViewById(R.id.textView);tv1.setText("首页");tv2.setText("朋友圈");
效果图:
Android布局文件之 include 详细介绍相关推荐
- [Android]Android布局文件中的android:id=@*属性使用方法汇总以及介绍
由于项目需要进行Android开发,因此一边开发,一边查阅资料,一边总结了Android布局文件中android:id="@*"属性的使用方法汇总以及介绍.id资源的引用 andr ...
- [免费专栏] Android安全之Android so文件分析「详细版」
也许每个人出生的时候都以为这世界都是为他一个人而存在的,当他发现自己错的时候,他便开始长大 少走了弯路,也就错过了风景,无论如何,感谢经历 Android安全付费专栏长期更新,本篇最新内容请前往: [ ...
- 【Android数据存储】ContentProvider详细介绍(附实例源码)
1.ContentProvider是什么? ContentProvider--内容提供者.它是一个类,这个类主要是对Android系统中进行共享的数据进行包装,并提供了一组统一的访问接口供其他程序调用 ...
- Xamarin Android布局文件没有智能提示
Xamarin Android布局文件没有智能提示 在Visual Studio 2015中,Android项目的Main.axml文件没有智能提示,不便于布局文件的编写.解决办法: (1)从Xama ...
- Android布局文件的布局方式
Android布局文件的属性值解析说明: 1.android:id [为控件指定相应的ID] 2.android:text [指定控件当中显示的文字,需要注意的是,这里尽量使用strings.xm ...
- Linux学习笔记 文件服务Vsftp详细介绍
Linux学习笔记 文件服务Vsftp详细介绍 知识点: 1.FTP使用TCP连接和TCP端口 2.在进行通信时,FTP需要建立两个TCP连接: 一个用于控制信息,TCP端口号缺省为21 一个用于数据 ...
- Android mmap 文件映射到内存介绍
本文链接: Android mmap 文件映射到内存介绍 Android开发中,我们可能需要记录一些文件.例如记录log文件.如果使用流来写文件,频繁操作文件io可能会引起性能问题. 为了降低写文件的 ...
- Android布局文件错误,android 布局文件常见错误
1.'Missing contentDescription attribute on image' in XML 原因:缺少图片描述,在 ADT 16 开始会抛出这个警告,确保开发者为图片添加内容描述 ...
- android布局中使用include及需注意点
在android布局中,使用include,将另一个xml文件引入,可作为布局的一部分,但在使用include时,需注意以下问题:一.使用include引入如现有标题栏布局block_header.x ...
最新文章
- 桌面虚拟化场景中对存储系统IO性能的评估方法
- 阿里集团搜索和推荐关于效率稳定性的思考和实践
- oracle ha节点,oracle linux ha配置
- 差分放大电路差模共模公式_选择正确的放大器
- c语言 指针 pdf,深入理解c指针 PDF扫描版[33MB]
- Ambari架构源码解析
- 获取PowerShell某个对象的所有命令
- SilverLight企业应用框架设计【一】整体说明
- 浅谈JavaScript代码预解析 + 示例详解
- 入侵检测——masscan(扫描篇)
- 【BZOJ3717】[PA2014]Pakowanie 状压DP
- weui UI库适用范围
- 树莓派3B+无显示屏安装教程(一)
- 网页通栏广告的编写技巧
- 贝叶斯系列:(三)贝叶斯网络
- angelababy都靠它保持身材,只需10秒随时随地喝到新鲜果汁!
- STM32F10xxx中文板参考手册PDF(内有英文版链接)
- 最新!国产操作系统大盘点(附链接)
- 【Chrome】在mac深色主题下,chrome依旧保持浅色风格
- 2D游戏引擎Allegro 系列教程(二) Hello world!