当前位置: 移动技术网 > IT编程>移动开发>Android > Android入门之LinearLayout、AbsoluteLayout的用法实例讲解

Android入门之LinearLayout、AbsoluteLayout的用法实例讲解

2019年07月24日  | 移动技术网IT编程  | 我要评论

cooilove,监控技术,轻骑者

本文实例介绍了android中linearlayout、absolutelayout的用法,希望能对于初学android的朋友起到一点帮助作用。具体内容如下:

android 的ui 布局都以layout 作为容器,并且在上面按照规定排列控件,这方面跟java 的swing 和lwuit 很像。控件跟layout 有很多属性是一样的,可以在properties 里面修改,跟.net/delphi 等rad 类似,其中最常用的属性有以下这些:

id="@+id/edtinput",id 是连接ui 与代码的桥梁

gravity= "center" ,layout 中的控件居中

layout_width="fill_parent" ,自动填充至屏幕宽度,layout_height 同理

layout_width="wrap_content" ,自动填充为控件大小,layout_height 同理

linearlayout ,在android入门实例一篇所用的layout 就是linearlayout ,它的理解很简单:在linearlayout 里面的控件,按照水平或者垂直排列:
orientation="horizontal" :水平排列;orientation=" vertical" :垂直排列
当linearlayout 是horizontal ,并且里面的控件使用了layout_width="fill_parent" ,第二组控件会挡在屏幕的右边,那也就是看不到了。

absolutelayout ,是一个按照绝对坐标定义的布局,由于使用绝对坐标去定位控件,因此要实现自适应界面时,应尽少使用 absolutelayout 。 absolutelayout 里面的控件都以layout_x 、layout_y 来定义其位置:

 

上图中的textview01的x坐标为10px,y坐标为10px,页面布局代码如下:

<absolutelayout android:id="@+id/absolutelayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" > 
<textview android:text="textview01" android:id="@+id/textview01" android:layout_height="wrap_content" android:layout_y="10px" android:layout_width="wrap_content" android:layout_x="110px"> 
</textview> 
</absolutelayout>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网