在Android界面xml文件中可以导入另一个xml文件,就能实现一个功能就是重复利用相同的xml布局

有两种方法进行处理:

include引入

定义一个布局Tab_flag.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:gravity="center_vertical"
android:maxHeight="160dp" > <ImageButton
android:id="@+id/weather_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/index_btn"
android:src="@drawable/j5" /> <View
android:id="@+id/items_divider_h"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#929292" /> <View
android:id="@+id/items_divider_v"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#929292" /> </RelativeLayout>

在另一个布局中引用这个布局

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/init_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*" > <TableRow> <include
android:id="@+id/button1"
android:layout_height="160dp"
android:layout_gravity="center"
layout="@layout/tableitemview" /> <include
android:id="@+id/button2"
android:layout_height="160dp"
android:layout_gravity="center"
layout="@layout/tableitemview" /> <include
android:id="@+id/button3"
android:layout_height="160dp"
android:layout_gravity="center"
layout="@layout/tableitemview" />
</TableRow> <TableRow>
<include
android:layout_height="160dp"
android:layout_gravity="center"
layout="@layout/tableitemview" /> <include
android:layout_height="160dp"
android:layout_gravity="center"
layout="@layout/tableitemview" /> <include
android:layout_height="160dp"
android:layout_gravity="center"
layout="@layout/tableitemview" />
</TableRow> </TableLayout>

其中,

android:stretchColumns="*" 
stretchColumns是自适应宽度的属性,如果属性值为“*”则所有的空间都是自适应宽度,如果为“1”是设置TableLayout所有行的第二列为扩展列。也就是说如果没行都是三列的话,剩余的空间由第二列不齐。  <!-- include标签内不能设置RelativeLayout属性,如android:layout_alignParentBottom,因为不起作用 -->   
<!-- include标签内设置id属性后(android:id),其引用的布局layout内的id属性就不起作用了,怀疑是其引用的layout外层包裹了一层include标签或者是覆盖了其内的属性id-->   
<!-- 如果没有include标签,所有布局代码都写在一个xml文件中,界面会显得很冗余,可读性很差。而且界面加载的时候是按照顺序加载的,前面的布局不能调用其后面的布局id。而采用include后,一个include中可以引用其后的include中的布局id属性 -->

merage引入

<LinearLayout
android:layout_width="100px"
android:layout_height="wrap_content">
<include layout="@layout/anotherlayout"/>
</LinearLayout> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<Button android:id = "@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮"/>
</merge>

这里还是没有解决一个问题,怎么样自定义相同布局中的不同内容呢?

当然是在java中写了。

TableLayout中怎么填充相同的布局的更多相关文章

  1. Android中常用的5大布局详述

    Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面. 所有的布局方式都可以归类为ViewGroup的 ...

  2. VS中C++对象的内存布局

    本文主要简述一下在Visual Studio中C++对象的内存布局,这里没有什么测试代码,只是以图文的形式来描述一下内存分布,关于测试的代码以及C++对象模型的其他内容大家可以参考一下陈皓先生的几篇博 ...

  3. 浅谈CSS3中display属性的Flex布局

    浅谈CSS3中display属性的Flex布局   最近在学习微信小程序,在设计首页布局的时候,新认识了一种布局方式display:flex 1 .container { 2 display: fle ...

  4. UI篇--Android中TableLayout中的布局

        表格布局是按照行列来组织子视图的布局.表格布局包含一系列的Tablerow对象,用于定义行(也可以使用其它子对象).表格布局不为它的行.列和单元格显示表格线.每个行可以包含个以上(包括)的单元 ...

  5. Android中ListView同过自定义布局并使用SimpleAdapter的方式实现数据的绑定

    1.listview的数据填充可以通过ArrayAdapter,SimpleAdapter,也可以是一个xml文件,但是ArrayAdapter与SimpleAdapter的区别是: 2 ArrayA ...

  6. TableLayout中stretchColumns、shrinkColumns的使用方法

    android:stretchColumns="1" android:shrinkColumns="1"这两个属性是TableLayout所特有的,也是这两个属 ...

  7. JVM高级特性-二、JVM在堆中对象的分配、布局、访问过程

    前面介绍了jvm运行时数据区域后,下面讲解下对内存中数据的其他细节,看他们是如何创建.布局及访问的 一.对象的创建 1.对象的分配 对象的创建分配方式主要有两种:指针碰撞和空闲列表 指针碰撞: 假设堆 ...

  8. Python tkinter调整元件在窗口中的位置与几何布局管理

    Tkinter中的GUI总是有一个root窗口,不管你是主动或者别动获得.主窗口就是你的程序开始运行的时候创建的,在主窗口中你通常是放置了你主要的部件.另外,Tkinter脚本可以依据需要创建很多独立 ...

  9. javaFX中解决填充(拉伸)问题

    1.margin设置实现 在项目过程中,遇到此问题,如图: 如果窗口缩小,HBox(左边的包含TitledPane那部分)看不到底部 如果窗口拉大,下面就出现空白,HBox高度没拉神 办法:对包含HB ...

随机推荐

  1. RS-232协议和RS-485协议

    RS232 RS232是一种异步传输标准接口.通常 RS-232 接口以9个引脚 (DB-9) 或是25个引脚 (DB-25) 的型态出现 .RS232最经常使用的连接方式是三根线:一条发送线.一条接 ...

  2. OAuth和OpenID的区别(转)

    OAuth(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方应用.  OAuth协议为用户资源的授权提 ...

  3. java.lang.Runnable接口

    大家都知道使用线程的2种方式,一是继承Thread类,二是实现Runnable接口.实际上,即使你实现了Runnable接口,终于还是要构造一个Thread类的对象.看过Thread源码发现,事实上这 ...

  4. 编程算法 - 数丑陋 代码(C)

    数丑陋 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 我们把仅仅包括因子2, 3 和 5的数称作丑数. 求按从小到大的顺序的第5个丑数. 能够 ...

  5. Developer Tool - 1. Text Tool and GNU/Linux Tool

    Below two links list famous tool about text processing and provide a good category. And it will give ...

  6. Codeforces 420 B. Online Meeting

    B. Online Meeting time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. (一)spring MVC基本概念和流程

    MVC的概念 Model(模型):包含数据和行为.不过现在一般都分离开来:Value Object(数据) 和 服务层(行为). View(视图):负责进行模型的展示,一般就是展示给用户的界面. Co ...

  8. Fireasy

    Fireasy与Asp.net MVC结合   Fireasy之前都是使用HttpService来为jquery ajax提供服务,这个HttpService实际上和MVC的原理机制是一样的,只是它支 ...

  9. C#关于HttpClient的应用(二):极光推送IM集成

    public class JPushClient:BaseHttpClient { private String appKey; private String masterSecret; public ...

  10. 华为-on练习--身高找到最好的二人

    称号: 离5个人选择2个人作为礼工具.中的每个个体的身高的范围160-190,要求2个人高差值至少(假设差异值一样,他们中最高的选择).输出的两个人的身高升序. Smple input:161 189 ...