Android布局整合include界面控件(重用布局)

2014-11-24 08:39:38 来源: 作者: 浏览: 1

说了那么多,其实使用并不难,而且还很简单,那接下来我们来举例来看看,看了包懂,不懂不收钱,其实也没收钱哈。


由于是讲布局的安排跟组合,那我们这里就只拿布局文件来解析下,其他程序代码跟其他程序没区别。


这里我们以最简单的控件TextView来举例,总共假设3个布局文件,其中一个布局包含了其他两个子布局。


父布局layoutP:


< xml version="1.0" encoding="utf-8" >
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

android:layout_width="fill_parent"
layout="@layout/includeB" />

< xml version="1.0" encoding="utf-8" >
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

android:layout_width="fill_parent"
layout="@layout/includeB" />



子布局layoutA:


< xml version="1.0" encoding="utf-8" >
android:text="随时随地,即兴时代!"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

< xml version="1.0" encoding="utf-8" >
android:text="随时随地,即兴时代!"
android:layout_width="wrap_content"
android:layout_height="wrap_content">


子布局二layoutB:


< xml version="1.0" encoding="utf-8" >
android:text="ATAAW.COM"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

< xml version="1.0" encoding="utf-8" >
android:text="ATAAW.COM"
android:layout_width="wrap_content"
android:layout_height="wrap_content">


通过以上layoutP中的整合,layoutA与layoutB就成为layoutP中的子元素,不仅使得整个布局代码结构清晰,提高了可读性,而且可以将界面排版中的功能模块清楚的划分。


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: