Android 之布局(二)

3、TableLayout(表格布局)

像表格一样布局,通常情况下,TableLayout有多个TableRow组成,每个TableRow就是一行。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:shrinkColumns="2">
    <TableRow>
        <Button android:text="Button1"/>
        <Button android:text="Button2"/>
        <Button android:text="Button3"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button4"/>
        <Button android:text="Button5"/>
        <Button android:text="Button6"/>
    </TableRow>
    <TableRow>
        <Button android:text="Button7"/>
        <Button android:text="Button8"/>
        <Button android:text="Button9"/>
    </TableRow>
</TableLayout>

总结:常用属性:

[1]shrinkColumns属性:以0行为序,当TableRow里面的控件布满布局时,指定列自动延伸以填充可用部分;当TableRow里面的控件还没有布满布局时,shrinkColumns不起作用。(android:shrinkColumns="2",第3列布满时填充)

[2]strechColumns属性:以第0行为序,指定列对空白部分进行填充。(android:strechColumns="2",第3列填充)

[3]collapseColumns属性:以0行为序,隐藏指定的列.。(android:strechColumns="2",隐藏第3列)

[4]layout_column属性:以0行为序,设置组件显示指定列。(android:layout_column="2",显示在第三列)

[5]layout_span属性:以第0行为序,设置组件显示占用的列数。(android:layout_span="3",占用3列)

4、AbsoluteLayout(绝对布局)

组件的位置可以准确的指定其在屏幕的x/y坐标位置。虽然可以精确的去规定坐标,但是由于代码的书写过于刚硬,使得在不同的设备,不同分辨率的手机移动设备上不能很好的显示应有的效果,所以此布局不怎么被推荐使用。

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button1"
        android:layout_x="100dp"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button2"
        android:layout_y="100dp"
        />

</AbsoluteLayout>

5、FrameLayout(单帧布局)

据说是五种布局中最简单的一种,因为单帧布局在新定义组件的时候都会将组件放置屏幕的左上角,即使在此布局中定义多个组件,后一个组件总会将前一个组件所覆盖,除非最后一个组件是透明的。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button1"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Button2"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3"
        />

</FrameLayout>
时间: 2024-08-06 08:18:22

Android 之布局(二)的相关文章

Android学习系列(二)布局管理器之线性布局及其自定义实现

转载请注明出处:http://blog.csdn.net/lhy_ycu/article/details/39643669 LinearLayout是Android控件中的线性布局控件,它包含的子控件将以横向(HORIZONTAL)或竖向(VERTICAL)的方式排列,按照相对位置来排列所有的子控件及引用的布局容器.超过边界时,某些控件将缺失或消失.因此一个垂直列表的每一行只会有一个控件或者是引用的布局容器. 一.LinearLayout线性布局的相关属性说明: android:orientat

【ALearning】第四章 Android Layout组件布局(二)

前面我们分别介绍和学习了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoluteLayout(绝对布局).这次我们要进行RelativeLayout(相对布局)和TableLayout(表格布局)的学习.这部分是很重要的知识点.RelativeLayout是开发过程中强烈建议使用的,而TableLayout是满足一些特定需求时(常见表格显示,但不局限于此)需要使用. [博客专栏:http://blog.csdn.net/column/details/alearn

Android学习笔记二十五之ListView多布局实现

Android学习笔记二十五之ListView多布局实现 这一节是介绍ListView这个控件的最后一节,实现一个Item的多布局.像我们经常在用的各种即时通讯工具,QQ.微信等,假设他们的会话界面是ListView实现的,那么ListView就有多种Item布局,这一节,我们就来实现一个ListView的多种Item. 要实现ListView里面有多种Item,就要重写适配器的两个方法getViewTypeCount()和getItemViewType(int position),第一个方法是

Android常用界面布局(二)

ImageView ScaleType属性, 该属性用以表示显示图片的方式 ①matrix               根据一个3x3的矩阵对其中图片进行缩放 ②fitXY                  将图片非等比例缩放到大小与ImageView相同 ③fitStart               缩放方式同FIT_CENTER,只是将图片显示在左方或上方,而不是居中 ④fitCenter           ImageView的默认状态,大图等比例缩小,小图等比例放大,整体居中显示在Im

Android UI布局与控件(二)

一.View类的常用xml属性:[了解] ①.Android中所有的UI(用户界面)元素都是使用View和ViewGroup对象建立的 ②.View是一个可以将一些信息绘制在屏幕上并与用户产生交互的对象 ③.ViewGroup是一个包含多个的View和ViewGroup的容器,用来定义UI布局. ④.Android提供了一系列的View和ViewGroup的子类,开发者可以灵活地组合使用它们来完成界面布 局.界 面元素绘制和用户交互等工作 ⑤.开发者还可以选择性地继承一些系统提供的View,来自

浅谈Android五大布局(二)——RelativeLayout和TableLayout

在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局RelativeLayout(相对布局)和TableLayout(表格布局)相对之前布局结构稍显复杂一点,所以这里另起篇幅进行介绍. RelativeLayout: RelativeLayout按照各子元素之间的位置关系完成布局.在此布局中的子元素里与位置相关的属性将生效.例如android:layout_be

浅谈Android五大布局(二)——RelativeLayout和TableLayout【转】

http://www.cnblogs.com/wisekingokok/archive/2011/08/24/2152004.html 在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局RelativeLayout(相对布局)和TableLayout(表格布局)相对之前布局结构稍显复杂一点,所以这里另起篇幅进行介绍. RelativeLayout: Relat

浅谈Android五大布局

Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Android的五大布局分别是LinearLayout(线性布局).FrameLayout(单帧布局).RelativeLayout(相对布局).AbsoluteLayout(绝对布局)和TableLayout(表格布局). LinearLayout: LinearLayout按照垂直或者水平的顺序依次排列子元素,每一个子元素都位于前一个元素之后

iOS中xib与storyboard原理,与Android界面布局的异同

用文本标记语言来进行布局,用的最多的应该是HTML语言.HTML可以理解为有一组特殊标记的XML语言. 一.iOS中xib与storyboard显示原理 在iOS中主要的布置界面的方式有3种:代码,xib,storyboard. 1. 代码 代码布置界面是万能的,但通常很复杂.布置一个简单的界面可能需要很多行代码,因此十分繁琐. 下面为创建一个按钮的代码,最少也要3行: UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd

android利用zbar二维码扫描-(解决中文乱码及扫描区域定义)

写在最前(这是对上一篇博文的问题做的更新[android利用zbar二维码扫描]) project下载   zbarLib编译project  project下载0积分 bug 在2.3的系统中Holder须要设置type,否则会黑屏(感谢网友[(α ⒎待sんа)294439435]) com.example.qu.MainActivity的第50行mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 今天发现 在com.exampl