Android之五大布局

布局里的普通属性:
layout_width 定义主件相对父容器的宽度
layout_height 定义主件相对父容器的高度
match_parent 充满父容器
wrap_content 完全包裹自己的内容
android:text 显示文本内容
TextView以及子类才有显示文本内容的功能

android:orientation定义主件的排列的方式

horizontal 水平排列
vertica 垂直排列

1)linearLayout线性布局
默认的排列方式是水平排列方式

<LinearLayout 
android:orientation="vertical"垂直
 android:gravity="center"> 
 <TextView
android:layout_weight="1">  这个属性按照权重来瓜分布局
共同的属性:
android:gravity设置组件的内容对齐方式 如按钮里的文本
android:layout_gravity="center"设置组件在父容器中的对齐方式
android:layout_width="wrap_content"相对于父容器
android:layout_height="wrap_content"

2)RelativeLayout:相对布局
相对布局容器内子组件的位置总是相对兄弟组件,父容器来决定的。
如果没有设置属性相对布局和单帧布局是类似的。
这里写图片描述
代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_centerInParent="true"
        android:id="@+id/center"/>
     <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_above="@id/center"
        android:layout_alignLeft="@id/center"/>
     <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_below="@id/center"
        android:layout_alignLeft="@id/center"/>
       <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_toLeftOf="@id/center"
        android:layout_alignTop="@id/center"/>
       <ImageView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:layout_toRightOf="@id/center"
        android:layout_alignTop="@id/center"
        />
    <RelativeLayout 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#d22422"
        >
        <Button 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="回退"
        android:layout_alignParentLeft="true"/>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="微信"
        android:layout_centerInParent="true"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:layout_alignParentRight="true"
        android:text="发送" />

    </RelativeLayout>


</RelativeLayout>

效果如图:

这里写图片描述

3)TableLayout:表格布局
TableRow来表示一行
android:collapseColumns: 隐藏某列
android:stretchColumns:扩展某列,为了充满父容器的行
值是数字,从0开始,如果有多个数字用逗号隔开
4)单帧布局 FrameLayout 只有一个位置可以显示内容.
单帧布局的所有组件都放在容器的左上角。
霓虹灯的效果
5)绝对布局 AbsoluteLayout
这种布局现在已经丢弃了,不怎么用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值