文章 百度网站创建及发展历史,友情链接有哪些展现形式,上海网站推广软件,中信建设有限责任公司招标2019独角兽企业重金招聘Python工程师标准 看到好的技术教程就想分享一下#xff0c;不喜勿喷#xff01;谢谢配合#xff0c;仅供菜鸟学习研究(^o^)/~ 友情推荐《爱加密》Android apk加密保护视频教程剪辑#xff1a;http://www.ijiami.cn/Video?v3 Andro… 2019独角兽企业重金招聘Python工程师标准 看到好的技术教程就想分享一下不喜勿喷谢谢配合仅供菜鸟学习研究(^o^)/~ 友情推荐《爱加密》Android apk加密保护视频教程剪辑http://www.ijiami.cn/Video?v3 Android的界面是有布局和组件协同完成的布局好比是建筑里的框架而组件则相当于建筑里的砖瓦。组件按照布局的要求依次排列就组成了用户所看见的界面。 所有的布局方式都可以归类为ViewGroup的5个类别即ViewGroup的5个直接子类。其它的一些布局都扩展自这5个类。 1.LinearLayout线性布局方式 这种布局比较常用也比较简单就是每个元素占一行当然也可能声明为横向排放也就是每个元素占一列。 LinearLayout按照垂直或者水平的顺序依次排列子元素每一个子元素都位于前一个元素之后。如果是垂直排列那么将是一 个N行单列的结构每一行只会有一个元素而不论这个元素的宽度为多少如果是水平排列那么将是一个单行N列的结构。如果搭建两行两列的结构通常的方 式是先垂直排列两个元素每一个元素里再包含一个LinearLayout进行水平排列。 LinearLayout中的子元素属性 android:layout_weight生效它用于描述该子元素在剩余 空间中占有的大小比例。加入一行只有一个文本框那么它的默认值就为0如果一行中有两个等长的文本框那么他们的 android:layout_weight值可以是同为1。如果一行中有两个不等长的文本框那么他们的android:layout_weight值 分别为1和2那么第一个文本框将占据剩余空间的三分之二第二个文本框将占据剩余空间中的三分之一。android:layout_weight遵循数 值越小重要度越高的原则。 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_widthfill_parent android:layout_heightwrap_content android:background#ff000000 android:textstring/hello/ LinearLayout android:orientationhorizontal android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_widthfill_parent android:layout_heightwrap_content android:background#ff654321 android:layout_weight1 android:text1/ TextView android:layout_widthfill_parent android:layout_heightwrap_content android:background#fffedcba android:layout_weight2 android:text2/ /LinearLayout /LinearLayout 2.Relative Layout相对布局 RelativeLayout按照各子元素之间的位置关系完成布局。在此布局中的子元素里与位置相关的属性将生效。例如androidlayout_below, android:layout_above, android:layout_centerVertical等。注意在指定位置关系时引用的ID必须在引用之前先被定义否则将出现异常。 RelativeLayout是Android五大布局结构中最灵活的一种布局结构比较适合一些复杂界面的布局。 ?xml version1.0 encodingutf-8? RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:idid/text_01 android:layout_width50dp android:layout_height50dp android:background#ffffffff android:gravitycenter android:layout_alignParentBottomtrue android:text1/ TextView android:idid/text_02 android:layout_width50dp android:layout_height50dp android:background#ff654321 android:gravitycenter android:layout_aboveid/text_01 android:layout_centerHorizontaltrue android:text2/ TextView android:idid/text_03 android:layout_width50dp android:layout_height50dp android:background#fffedcba android:gravitycenter android:layout_toLeftOfid/text_02 android:layout_aboveid/text_01 android:text3/ /RelativeLayout 3.AbsoluteLayout绝对位置布局 在此布局中的子元素的android:layout_x和android:layout_y属性将生效用于描述该子元素的坐标位置。屏幕左上角为坐标原点0,0第一个0代表横坐标向右移动此值增大第二个0代表纵坐标向下移动此值增大。在此布局中的子元素可以相互重叠。在实际开发中通常不采用此布局格式因为它的界面代码过于刚性以至于有可能不能很好的适配各种终端。 ?xml version1.0 encodingutf-8? AbsoluteLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_width50dp android:layout_height50dp android:background#ffffffff android:gravitycenter android:layout_x50dp android:layout_y50dp android:text1/ TextView android:layout_width50dp android:layout_height50dp android:background#ff654321 android:gravitycenter android:layout_x25dp android:layout_y25dp android:text2/ TextView android:layout_width50dp android:layout_height50dp android:background#fffedcba android:gravitycenter android:layout_x125dp android:layout_y125dp android:text3/ /AbsoluteLayout 4.FrameLayout帧布局 FrameLayout是五大布局中最简单的一个布局可以说成是层布局方式。在这个布局中整个界面被当成一块空白备用区域所有的子元素都不能被指定放置的位置它们统统放于这块区域的左上角并且后面的子元素直接覆盖在前面的子元素之上将前面的子元素部分和全部遮挡。如下第一个TextView被第二个TextView完全遮挡第三个TextView遮挡了第二个TextView的部分位置。 ?xml version1.0 encodingutf-8? FrameLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_widthfill_parent android:layout_heightfill_parent android:background#ff000000 android:gravitycenter android:text1/ TextView android:layout_widthfill_parent android:layout_heightfill_parent android:background#ff654321 android:gravitycenter android:text2/ TextView android:layout_width50dp android:layout_height50dp android:background#fffedcba android:gravitycenter android:text3/ /FrameLayout 5.TableLayout表格布局 适用于N行N列的布局格式。一个TableLayout由许多TableRow组成一个TableRow就代表TableLayout中的一行。 TableRow是LinearLayout的子类ablelLayout并不需要明确地声明包含多少行、多少列而是通过TableRow以及其他组件来控制表格的行数和列数 TableRow也是容器因此可以向TableRow里面添加其他组件没添加一个组件该表格就增加一列。如果想TableLayout里面添加组件那么该组件就直接占用一行。在表格布局中列的宽度由该列中最宽的单元格决定整个表格布局的宽度取决于父容器的宽度默认是占满父容器本身。 TableLayout继承了LinearLayout因此他完全可以支持LinearLayout所支持的全部XML属性除此之外TableLayout还支持以下属性 XML属性 相关用法 说明 1. andriodcollapseColumns setColumnsCollapsedint boolean 设置需要隐藏的列的序列号多个用逗号隔开 2.androidshrinkColumns setShrinkAllColumnsboolean 设置被收缩的列的序列号多个用逗号隔开 3.androidstretchColimns setSretchAllColumndsboolean 设置允许被拉伸的列的序列号多个用逗号隔开 ?xml version1.0 encodingutf-8? TableLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TableRow android:layout_widthfill_parent android:layout_heightwrap_content TextView android:background#ffffffff android:gravitycenter android:padding10dp android:text1/ TextView android:background#ff654321 android:gravitycenter android:padding10dp android:text2/ TextView android:background#fffedcba android:gravitycenter android:padding10dp android:text3/ /TableRow TableRow android:layout_widthfill_parent android:layout_heightwrap_content TextView android:background#ff654321 android:gravitycenter android:padding10dp android:text2/ TextView android:background#fffedcba android:gravitycenter android:padding10dp android:text3/ /TableRow TableRow android:layout_widthfill_parent android:layout_heightwrap_content TextView android:background#fffedcba android:gravitycenter android:padding10dp android:text3/ TextView android:background#ff654321 android:gravitycenter android:padding10dp android:text2/ TextView android:background#ffffffff android:gravitycenter android:padding10dp android:text1/ /TableRow /TableLayout 转载于:https://my.oschina.net/1590538xiaokai/blog/507658