Android UI布局

一、线性布局(LinearLayout)

1、线性布局主要分为垂直和水平两种布局方向
默认是水平布局android:orientation="horizontal"
设置为垂直布局android:orientation="vertical"
2、可以设置颜色、字体
3、可以嵌套使用

  <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账号:" />

        <EditText
            android:layout_width="260dp"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码:" />

        <EditText
            android:layout_width="260dp"
            android:layout_height="wrap_content" />

    </LinearLayout>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录:" />

在这里插入图片描述
4、可以使用自适应weight属性

二、相对布局(RelativeLayout)

1、在设计的时候更方便控件位置的摆放
2、可以和线性布局嵌套使用

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:id="@+id/menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="menu"
            android:layout_centerInParent="true"
            />
        <Button
            android:id="@+id/top"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_above="@+id/menu"
            android:layout_centerInParent="true"
            />
        <Button
            android:id="@+id/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_toRightOf="@+id/menu"
            android:layout_centerInParent="true"
            />
        <Button
            android:id="@+id/bottom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_below="@+id/menu"
            android:layout_centerInParent="true"
            />
        <Button
            android:id="@+id/left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_toLeftOf="@+id/menu"
            android:layout_centerInParent="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_above="@+id/menu"
            android:layout_toLeftOf="@+id/top"
            android:layout_centerInParent="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_above="@+id/right"
            android:layout_toRightOf="@+id/top"
            android:layout_centerInParent="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_below="@+id/left"
            android:layout_toLeftOf="@+id/bottom"
            android:layout_centerInParent="true"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_below="@+id/right"
            android:layout_toRightOf="@+id/bottom"
            android:layout_centerInParent="true"
            />
    </RelativeLayout>

在这里插入图片描述

三、网格布局(GridLayout)

1、设置总行数、总列数、指定布局方向

   android:orientation="horizontal"
   android:rowCount="6"
   android:columnCount="4"

2、合并行或列

android:layout_columnSpan="4"
android:layout_gravity="fill"

3、一行占位不够,会自动将控件挤到下一行

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值