Android中怎么实现页面布局

发布时间:2021-07-19 15:15:03 作者:Leah
来源:亿速云 阅读:244

这期内容当中小编将会给大家带来有关Android中怎么实现页面布局,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1、gravity

gravity 这个英文单词是重心的意思,在这里就表示停靠位置的意思。

android:gravity是对元素本身说的,元素本身的文本显示在什么地方靠着换个属性设置,不过不设置默认是在左侧的。

android:layout_gravity是相对与它的父元素说的,说明元素显示在父元素的什么位置。

比如说button: android:layout_gravity 表示按钮在界面上的位置。 android:gravity表示button上的字在button上的位置。

可选值:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fill_horizontal、center、fill、clip_vertical。

而且这些属性是可以多选的,用“|”分开,默认这个的值是:Gravity.LEFT

2、layout_weight

layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。

所有的视图都有一个layout_weight值,默认为零,意思是需要显示多大的视图就占据多大的屏幕空间。若赋一个高于零的值,则将父视图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight 值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布局的layout_weight值中所占的比率而定。

举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。

该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个文本编辑元素其中***个的layout_weight值设置为1,而第二个的设置为2,

则剩余空间的三分之二分给***个,三分之一分给第二个(数值越小,重要度越高)。

Android中怎么实现页面布局

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/bg02"

android:orientation="horizontal" >

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="4"

android:orientation="vertical" >

android:id="@+id/txtSpace1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="" />

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

android:orientation="vertical" >

android:id="@+id/txtSpace2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="" />

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/mn_01" />

android:id="@+id/button2"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/mn_02" />

android:id="@+id/button3"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/mn_03" />

android:id="@+id/button4"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/mn_04" />

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="4"

android:orientation="vertical" >

android:id="@+id/txtSpace3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="" />

上述就是小编为大家分享的Android中怎么实现页面布局了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. HTML页面布局
  2. 页面布局和设备适配

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:ListView中怎么动态加载数据模板

下一篇:python中的EasyOCR库是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》