TableLayout中怎么填充相同的布局
在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中怎么填充相同的布局的更多相关文章
- Android中常用的5大布局详述
Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面. 所有的布局方式都可以归类为ViewGroup的 ...
- VS中C++对象的内存布局
本文主要简述一下在Visual Studio中C++对象的内存布局,这里没有什么测试代码,只是以图文的形式来描述一下内存分布,关于测试的代码以及C++对象模型的其他内容大家可以参考一下陈皓先生的几篇博 ...
- 浅谈CSS3中display属性的Flex布局
浅谈CSS3中display属性的Flex布局 最近在学习微信小程序,在设计首页布局的时候,新认识了一种布局方式display:flex 1 .container { 2 display: fle ...
- UI篇--Android中TableLayout中的布局
表格布局是按照行列来组织子视图的布局.表格布局包含一系列的Tablerow对象,用于定义行(也可以使用其它子对象).表格布局不为它的行.列和单元格显示表格线.每个行可以包含个以上(包括)的单元 ...
- Android中ListView同过自定义布局并使用SimpleAdapter的方式实现数据的绑定
1.listview的数据填充可以通过ArrayAdapter,SimpleAdapter,也可以是一个xml文件,但是ArrayAdapter与SimpleAdapter的区别是: 2 ArrayA ...
- TableLayout中stretchColumns、shrinkColumns的使用方法
android:stretchColumns="1" android:shrinkColumns="1"这两个属性是TableLayout所特有的,也是这两个属 ...
- JVM高级特性-二、JVM在堆中对象的分配、布局、访问过程
前面介绍了jvm运行时数据区域后,下面讲解下对内存中数据的其他细节,看他们是如何创建.布局及访问的 一.对象的创建 1.对象的分配 对象的创建分配方式主要有两种:指针碰撞和空闲列表 指针碰撞: 假设堆 ...
- Python tkinter调整元件在窗口中的位置与几何布局管理
Tkinter中的GUI总是有一个root窗口,不管你是主动或者别动获得.主窗口就是你的程序开始运行的时候创建的,在主窗口中你通常是放置了你主要的部件.另外,Tkinter脚本可以依据需要创建很多独立 ...
- javaFX中解决填充(拉伸)问题
1.margin设置实现 在项目过程中,遇到此问题,如图: 如果窗口缩小,HBox(左边的包含TitledPane那部分)看不到底部 如果窗口拉大,下面就出现空白,HBox高度没拉神 办法:对包含HB ...
随机推荐
- Docker contanier comunication with route
2台宿主机,hslave1 192.168.1.153, hslave2 192.168.1.154 修改网段 docker0默认网段是172.17.0.0/16,修改154机器的docker0的网段 ...
- NSIS脚本:在卸载页面收集信息
原文 NSIS脚本:在卸载页面收集信息 此功能用于在软件卸载时收集相关信息,以便进行后续改进.实现功能如图: 以下为实现代码: 01 !include nsDialogs.nsh 02 !includ ...
- ORA-00838: Specified value of MEMORY_TARGET is too small(转)
1. 测试环境OS: RHEL5U5(32bit)DB: Oracle 11.2.0.3.0(32bit) 2. 异常原因. 2.1 oracle 11g默认sga_target为0,如下图, O ...
- linux下面的中断处理软件中断tasklet机制
參考: <Linux内核设计与实现> http://blog.csdn.net/fontlose/article/details/8279113 http://blog.chinaunix ...
- Windows 8 – Reason 442: Failed to enable Virtual Adapter
Cisco VPN on Windows 8.1 – Reason 442: Failed to enable Virtual Adapter https://supertekboy.com/2013 ...
- Xcode-5.1.1更改文件盯作者
原来的文件默认是用户开机时的username ,网上说什么改通讯录事实上都是不正确的. 1.首先打开偏好设置,选择用户群组 2.进入用户界面 改动全名.此时要求你输入用户的password才干改动us ...
- /proc/mtd 各参数的含义 -- linux内核
经/proc虚拟文件系统读取MTD分区表:cat /proc/mtd mtd .name = raspi, .size = 0x00400000 (4M) .erasesize = 0x0001000 ...
- 怎样解决chm类型的文件在Windows操作系统中无法打开
又一次安装了Windows 7操作系统,发现chm文件类型Java API文档无法打开了,纠结了半天最终搞定,现总结一下: 1.选中该chm类型的文件,右键鼠标选择并点击"属性(R)&quo ...
- C++内存分配和拷贝构造函数写研究
昨晚参加笔试,开错题,有印象中的概念,但目前尚不清楚是怎么回事,什么原理,导致错误的话题.现在总结. 一.C++写内存分配研究 问题考察例如以下,请先不要看答案,看看你是否能做对,呵呵: waterm ...
- HBase加Solr
HBase加Solr 如何解决分布式系统数据事务一致性问题 (HBase加Solr) 摘要:对于所有的分布式系统,我想事务一致性问题是极其非常重要的问题,因为它直接影响到系统的可用性.本文以下所述所要 ...