关于Android的三种常用布局(TableLayout和AbsoluteLayout不常用,再次不做介绍)
来源:互联网 发布:linux tar zcvf命令 编辑:程序博客网 时间:2024/05/22 08:02
1.RelativeLayout相对布局:
可以用来设置元素与元素之间的一种位置的相对关系,就是子元素相对于父元素或者是兄弟元素的位置关系。其中包含有一系列的位置标签,在这里将其分为两类,第一类是子元素与父元素的相对位置设置,第二类是子元素与兄弟元素的相对位置设置。
(1) 子元素与父元素:
设置与父元素的对齐方式:
android:layout_alignParentTop=”true” 与父元素顶端对其
android:layout_alignParentBottom=”true” 与父元素顶端对其
android:layout_alignParentLeft=”true” 与父元素左端对其
android:layout_alignParentRight=”true” 与父元素右端对其
设置在父元素中的居中方式:
android:layout_centerInParent=”true” 在父元素中垂直方向和水平方向都居中
android:layout_centerHorizontal=”true” 在父元素中水平方向居中
android:layout_centerVertical=”true” 在父元素中垂直方向居中
以下是一段代码以及界面渲染图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左上" /> <Button android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="右上" /> <Button android:layout_alignParentBottom="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左下" /> <Button android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="左下" /> <Button android:id="@+id/btn_center" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居中" /></RelativeLayout>
(2) 子元素与兄弟元素:
对齐方式属性:(注意:属性值是id,不是Boolean值了)
android:layout_alignLeft=”@id/btn_center” 与指定元素左对齐
android:layout_alignRight=”@id/btn_center” 与指定元素右对齐
android:layout_alignTop=”@id/btn_center” 与指定元素顶端对齐
android:layout_alignBotton=”@id/btn_center” 与指定元素低端对齐
相对位置属性:
android:layout_toLeftOf=”@id/btn_center” 在指定元素的左侧
android:layout_toRightOf=”@id/btn_center” 在制定元素的右侧
android:layout_above=”@id/btn_center” 在指定元素的上面
android:layout_below=”@id/btn_center” 在指定元素的下面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#666666" > <Button android:id="@+id/btn_center" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居中" /> <Button android:layout_above="@id/btn_center" android:layout_alignLeft="@id/btn_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居上" /> <Button android:layout_below="@id/btn_center" android:layout_alignLeft="@id/btn_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居下" /> <Button android:layout_alignTop="@id/btn_center" android:layout_toLeftOf="@id/btn_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居左" /> <Button android:layout_alignTop="@id/btn_center" android:layout_toRightOf="@id/btn_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="居右" /></RelativeLayout>
2.LinearLayout线性布局:
线性布局是根据水平(Horizontal)或者垂直(Vertical)方向排列的布局方式,其最大的特点就是根据子元素的权重来分配视图的空间大小的。线性布局必须要设置属性:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" > <View android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1" android:background="#ffffff" /> <View android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="1" android:background="#ffff00" /> <View android:layout_height="match_parent" android:layout_width="0dp" android:layout_weight="2" android:background="#0000ff" /> </LinearLayout>
以上使用的是水平线性布局,其中视图中包含三个子元素,三个元素的权重值分别是1,1,2,即表示第一个元素的权重是1份,即占父元素宽度的1/4,第二个元素的占比也是1/4,第三个元素的占比是2/4.这是很好理解的。
(2) 垂直线性布局垂直线性布局基本上跟水平线性布局没有多大的区别,再次就不再多做赘述了。
3.FrameLayout帧布局
帧布局中的子视图总是被绘制到相对于屏幕的左上角上,所有添加到这个布局中的视图都是以层叠的方式显示,第一个添加到帧布局中的视图会被显示在最底层,最后一个放在最顶层,上一层的视图会覆盖下一层的视图。
- 关于Android的三种常用布局(TableLayout和AbsoluteLayout不常用,再次不做介绍)
- Android常用布局及属性--FrameLayout、TableLayout、 GridLayout、AbsoluteLayout、RelativeLayout
- Android常用的五大布局:LinearLayout/RelativeLayout/AbsoluteLayout/ TableLayout/FrameLayout
- Android中常用的五种布局方式:AbsoluteLayout
- Android中常用的五种布局方式:TableLayout
- Android 布局 之 TableLayout,RelativeLayout,AbsoluteLayout,FrameLayout
- Android 布局(LinearLayout\TableLayout\RelativeLayout\AbsoluteLayout\FrameLayout)
- Android 布局(LinearLayout\TableLayout\RelativeLayout\AbsoluteLayout\FrameLayout)
- Android布局(三)TableLayout
- 三种基本布局(不常用)以及全屏和Activity的两种启动方式
- TableLayout和relativelayout布局常用属性
- Android学习笔记(16):绝对布局AbsoluteLayout、常用距离单位
- Android常用布局的介绍
- Android五大布局对象 - FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android五大布局对象:FrameLayout,LinearLayout,AbsoluteLayout,RelativeLayout,TableLayout
- Android 五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- Android五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.
- android常用布局介绍
- 点击图片 , 获取图片上对应的坐标
- Debug Java applications remotely with Eclipse
- Ubuntu 搜狗输入法 一直全角问题
- [文章摘要]Towards Privacy-Preserving Semantic Mobility Analysis
- 随机选取算法 (有权重的记录中选取)
- 关于Android的三种常用布局(TableLayout和AbsoluteLayout不常用,再次不做介绍)
- 利用CADisplayLink 和 CAGradientLayer来实现文字渐变效果
- Android DatePickerDialog存在执行两次onDateSet BUG
- MySQL默认INFORMATION_SCHEMA,MySQL,TEST三个数据库用途
- Java DES 加密和解密源码
- PHP权重算法-用于游戏根据权限来随机物品
- Struts2 基于XML配置方式实现对action的所有方法进行校验
- 附近QQ采集软件/QQ附近人采集软件
- Jdk安装与环境变量配置