安卓常用布局学习

线性布局

布局方向
水平 android:orientation=“horizontal”
垂直android:orientation=“vertical”
gravity对齐方式–center
在这里插入图片描述
布局权重:视图中剩余部分的面积所占比例
android:layout_weight=“1”(数字)
水平布局:android:layout_width=“0dp”
垂直布局:android:layout_height=“0dp”

在这里插入图片描述

相对布局

子视图可通过相应的布局属性,设定相对于另一个兄弟视图或父视图容器的相对位置
1.相对与兄弟视图:
在这里插入图片描述
2.相对与父视图
在这里插入图片描述
3.对齐方式与间隔
android:paddingLeft="200dp"内部元素(字体…)间隔边缘的距离
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

帧布局

最简单的一种布局,没有任何定位方式,当我们往里面添加控件的时候,会默认把他们放到这块区域的左上角,帧布局的大小由控件中最大的子控件决定,如果控件的大小一样大的话,那么同一时刻就只能看到最上面的那个组件,后续添加的控件会覆盖前一个
在这里插入图片描述

网格布局

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:columnCount="4"
    android:rowCount="6"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_columnSpan="4"
        android:layout_gravity="fill"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:text="0" />
   <Button
       android:text="清空"
       android:layout_columnSpan="2"
       android:layout_gravity="fill"/>
    <Button
        android:text="消除"
        android:layout_columnSpan="2"
        android:layout_gravity="fill"/>
    <Button
        android:text="0" />
    <Button
        android:text="0"/>
    <Button
        android:text="0"/>
    <Button
        android:text="0"/>
    <Button
        android:text="0"/>
    <Button
        android:text="1"
        android:layout_row="4"
        android:layout_column="3"/>
</GridLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DQ_CODING

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值