Android界面布局中几种常用的布局
Android界面布局中几种常用的布局
在Android开发中,界面设计是开发过程中的一个很重要的部分,今天主要来给大家介绍一下Android开发中主要应用到的一些界面布局。
Android界面设计中应用较多的是以下几个布局:LinearLayout(线性布局)、TableLayout(表格布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)等、帧布局(FrameLayout)。接下来我将对它们来进行详细的介绍。
一、界面布局之线性布局(LinearLayout)
这种布局比较常用,也比较简单,就是每个元素占一行,把它按照横向排放,也就是每个元素占一列。在布局中都按照垂直或者水平的顺序依次排列子元素,每一个子元素都位于前一个元素之后。
(1)垂直线性布局
xmlns:tools="https://www.360docs.net/doc/e17944590.html,/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".MainActivity" >
图一:垂直线性布局(1)水平线性布局
将android:orientation="horizontal"设置为vertical,则他的方向为垂直的,具体效果如下图
图二:水平线性布局
二、界面布局之相对布局(RelativeLayout)
相对布局是android界面设计中比较常用和好用的一个布局方式。
1. 相对布局的属性
相对于兄弟元素
android:layout_below="@id/aaa":在指定View的下方
android:layout_above="@id/xxx":在指定View的上方
android:layout_toLeftOf="@id/bbb":在指定View的左边
android:layout_toRightOf="@id/cccc":在指定View的右边
相对于父元素
android:layout_alignParentLeft="true":在父元素内左边
android:layout_alignParentRight="true":在父元素内右边
android:layout_alignParentTop="true":在父元素内顶部
android:layout_alignParentBottom="true":在父元素内底部
对齐方式
android:layout_centerInParent="true":居中布局
android:layout_centerVertical="true":水平居中布局
android:layout_centerHorizontal="true":垂直居中布局
android:layout_alignTop="@id/xxx":与指定View的上边界一致
android:layout_alignBottom="@id/xxx":与指定View下边界一致
android:layout_alignLeft="@id/xxx":与指定View的左边界一致
android:layout_alignRight="@id/xxx":与指定View的右边界一致
间隔
android:layout_marginBottom=""; 离某元素底边缘的距离
android:layout_marginLeft=""; 离某元素左边缘的距离
android:layout_marginRight ="";离某元素右边缘的距离
android:layout_marginTop=""; 离某元素上边缘的距离
android:layout_paddingBottom=""; 离父元素底边缘的距离
android:layout_paddingLeft=""; 离父元素左边缘的距离
android:layout_paddingRight ="";离父元素右边缘的距离
android:layout_paddingTop=""; 离父元素上边缘的距离
2.用例说明
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000" > android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Type here:" android:textColor="#ffffff" android:textSize="30px"/> android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_background" android:layout_below="@id/label"/> android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10dip" android:textColor="#ffffff" android:text="OK" /> android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:textColor="#ffffff" android:text="Cancel" />
图三:相对布局
三、界面布局之表格布局(TableLayout)
表格布局采用行、列的形式来管理元素组件。TableLayout的行和列不需要声明,而是采用添加方法控制。
每次在TableLayout中添加一个TableRow,一个TableRow就代表表格中的一行,也同样是容器,往里面添加一个子组件就代表增加一列。在表格布局中,列的宽度由最宽的那个单元格决定,整个表格布局宽度取决于父容器的宽度。
用例表示:
android:layout_width="fill_parent" android:layout_height="fill_parent" > android:id="@+id/tableRow1" android:layout_height="wrap_content" android:gravity="center" > android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="用户名" /> android:id="@+id/userName" android:layout_weight="1" android:layout_height="wrap_content" /> android:id="@+id/tableRow2" android:layout_height="wrap_content" android:gravity="center"> android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码" /> android:id="@+id/password" android:layout_height="wrap_content" android:inputType="textPassword" /> android:id="@+id/tableRow4" android:layout_height="wrap_content" android:gravity="center" > android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登陆" /> android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消" />
图四:表格布局
四、界面布局之绝对布局(AbsoluteLayout)
特点:以坐标的方式来定位在屏幕上的位置,引起缺乏灵活性,在没有绝对定位的情况下相比其他类型的布局更难维护。 android:layout_width="fill_parent" android:layout_height="fill_parent" > android:id="@+id/lable1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="10dip" android:layout_y="10dip" android:text="inputname" /> android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_y="40dip" /> android:id="@+id/test1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="190dip" android:layout_y="100dip" android:width="70dip" android:text="OK" /> android:id="@+id/test2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="260dip" android:layout_y="100dip" android:width="70dip" android:text="Cancle" />
图五:绝对布局
五、界面布局之帧布局(FrameLayout)
FrameLayout是五大布局中最简单的一个布局。在帧布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。
用例所示:
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff000000" android:gravity="center" android:text="1"/> android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff654321" android:gravity="center" android:text="2"/> android:layout_width="50dp" android:layout_height="50dp" android:background="#fffedcba" android:gravity="center" android:text="3" />
以上来源于:长沙软件公司—小房子(如若侵权请及时联系本人,万分感谢!)
Android布局属性大全
Android布局属性大全 布局: AbsoluteLayout(绝对布局): xmlns:android="https://www.360docs.net/doc/e17944590.html,/apk/res/android" style="@..." android:clipChildren="true|false" android:clipToPadding="true|false" android:layoutAnimation="@---" android:animationCache="true|false" android:persistentDrawingCache="none|animation|scrolling|all":持续高速缓存绘图 android:alwaysDrawnWithCache="true|false" android:andStatesFromChildre="true|false" android:descendantFocusability="beforeDescendants|afterDescendants|bl ocksDescendants":后裔可聚焦 android:id="@+id/absoluteLayout" android:tag="@---" android:android:scrollX="---" android:android:scrollY="---" android:background="@---" android:padding="----" android:paddingLeft="----" android:paddingTop="----" android:paddingRight="----" android:paddingBotton="---" android:focusable="true|false" android:focusableInTouchMode="true|false" android:visibility="visible|invisible|gone" android:fitsSystemWindows="true|false":适合系统窗口 android:scrollbars="none|horizontal|vertical" android:scrollbarStyle="insideOverlay(内覆盖)|insideInset(内插 图)|outsideOverlay(外覆盖)|outsideInset(外插图)" android:isScrollContainer="true|false":是一个滚动集合 android:fadeScrollbars="true|false":褪色的滚动条 android:scrollbarFadeDuration="---":卷轴淡出 android:scrollDefaultDelayBeforeFade="---":滚动前默认延迟 android:scrollbarSize="---" android:scrollbarThumbHorizontal="@----":拇指水平滚动条 android:scrollbarThumbVertical="@----":拇指垂直滚动条 android:scrollbarTrackVertical="@---":垂直滚动条轨道 android:scrollbarTrackHorizontal="@---":水平滚动条轨道 android:scrollbarAlwaysDrawHorizontalTrack="true|false":水平滚动条总是吸引轨道
Android 开发之旅-view的几种布局方式及实践
Android 开发之旅:view的几种布局方式及实践 https://www.360docs.net/doc/e17944590.html,/1943397/363552 2010-06-06 14:14:00 标签:布局 View 实践移动开发 Android 原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处、作者信息和本声明。否则将追究法律责任。 https://www.360docs.net/doc/e17944590.html,/1943397/363552 引言 通过前面两篇: 1.Android 开发之旅:又见Hello World! 2.Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理及布局文件可谓有了比较深刻的认识和理解,并且用“Hello World!”程序来实践证明了。在继续深入Android开发之旅之前,有必要解决前两篇中没有介绍的遗留问题:View的几种布局显示方法,以后就不会在针对布局方面做过多的介绍。View的布局显示方式有下面几种:线性布局(Linear Layout)、相对布局(Relative Layout)、表格布局(Table Layout)、网格视图(Grid View)、标签布局(Tab Layout)、列表视图(List View)、绝对布局(AbsoluteLayout)。本文虽然是介绍View的布局方式,但不仅仅是这样,其中涉及了很多小的知识点,绝对能给你带来Android大餐! 本文的主要内容就是分别介绍以上视图的七种布局显示方式效果及实现,大纲如下: 1.1、View布局概述 2.2、线性布局(Linear Layout) 1. 2.1、Tips:android:layout_weight="1" 3.3、相对布局(Relative Layout) 4.4、表格布局(Table Layout) 5.5、列表视图(List View) 1. 5.1、一个小的改进 2. 5.2、补充说明 6.6、网格视图(Grid View) 7.7 、绝对布局() 8.8、标签布局(Tab Layout) 1、view的布局显示概述 通过前面的学习我们知道:在一个Android应用程序中,用户界面通过View和ViewGroup对象构建。Android中有很多种View和ViewGroup,他们都继承自View类。View对象是Android平台上表示用户界面的基本单元。 View的布局显示方式直接影响用户界面,View的布局方式是指一组View元素如何布局,准确的说是一个ViewGroup中包含的一些View怎么样布局。ViewGroup类是布局(layout)和视图容器(View container)的基类,此类也定义了https://www.360docs.net/doc/e17944590.html,youtParams类,它作为布局参数的基类,此类告诉父视图其中的子视图想如何显示。例如,XML布局文件中名为layout_something的属性(参加上篇的4.2节)。我们要介绍的View的布局方式的类,都是直接或间接继承自ViewGroup类,如下图所示:
Android七种布局解析
我们对Android应用程序运行原理及布局文件可谓有了比较深刻的认识和理解,并且用“Hello World!” 程序来实践证明了。在继续深入Android开发之旅之前,有必要解决前两篇中没有介绍的遗留问题:View 的几种布局显示方法,以后就不会在针对布局方面做过多的介绍。View的布局显示方式有下面几种: 线性布局(Linear Layout)、 相对布局(Relative Layout)、 表格布局(Table Layout)、 网格视图(Grid View)、 标签布局(Tab Layout)、 列表视图(List View)、 绝对布局(AbsoluteLayout)。本文虽然是介绍View的布局方式,但不仅仅是这样,其中涉及了很多小的知识点,绝对能给你带来Android大餐! 本文的主要内容就是分别介绍以上视图的七种布局显示方式效果及实现,大纲如下: ?1、View布局概述 ?2、线性布局(Linear Layout) o 2.1、Tips:android:layout_weight="1" ?3、相对布局(Relative Layout) ?4、表格布局(Table Layout) ?5、列表视图(List View) o 5.1、一个小的改进 o 5.2、补充说明 ?6、网格视图(Grid View) ?7 、绝对布局() ?8、标签布局(Tab Layout) 1、view的布局显示概述 通过前面的学习我们知道:在一个Android应用程序中,用户界面通过View和ViewGroup对象构建。A ndroid中有很多种View和ViewGroup,他们都继承自View类。View对象是Android平台上表示用户界面的基本单元。 View的布局显示方式直接影响用户界面,View的布局方式是指一组View元素如何布局,准确的说是一个ViewGroup中包含的一些View怎么样布局。ViewGroup类是布局(layout)和视图容器(View containe r)的基类,此类也定义了https://www.360docs.net/doc/e17944590.html,youtParams类,它作为布局参数的基类,此 类告诉父视图其中的子视图想如何显示。例如,XML布局文件中名为layout_so mething的属性(参加上篇的4.2节)。我们要介绍的View的布局方式的类,都是直接或间接继承自ViewGroup类,如下图所示:
Android_布局详解【图文】
Android 布局详解【图文】 Android 布局是开发中非常重要的一个知识部分,它的布局分为以下几种: Linear Layout:线性布局 Relative Layout:相对布局 Table Layout:表格布局 FrameLayout AbsoluteLayout Grid View:网格布局 Tab Layout:选项卡布局 List View:列表布局 一、Linear Layout 简单来说,直着排,横着排都可以,还可以嵌套,此布局运用的非常多。下面直接上示例代码及截图:
接下来,看一下布局XML文件: