【android】布局之盒模型、对齐方式、填充(类比web理解)

 

一、盒模型

我买了一盒月饼,月饼盒算是一个父容器,那月饼这个控件,距离月饼盒的边距是多少呢,这里就需要用到margin

margin是指从自身边框到另一个容器边框之间的距离,就是容器外距离。(外边距)

 

具体到android中的属性:

android:layout_marginLeft="20dp"

android:layout_marginTop="15dp

...

 

二、对齐方式

相对父控件的对齐方式,是对着左边还是右边还是中间呢

 

具体到安卓中的属性:

android:layout_gravity=“center"

...

事实证明,只要有父容器,无论是布局还是控件都可以用

 

 

三、填充

padding是指自身边框到自身内部另一个容器边框之间的距离,就是容器内距离。(内边距)

比如月饼印了一个花纹,月饼这个控件的花纹距离月饼的边是多少,就是padding了 

 

具体到安卓中的属性:

android:gravity=“bottom"

 

 

四、一个小例子

 

<?xml version="1.0" encoding="utf-8"?>

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

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

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    tools:context=".MainActivity">

 

    <RadioGroup

        android:id="@+id/radioGroup"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:orientation="horizontal"

        android:layout_gravity="center"

        android:layout_marginTop="150dp"

        >

 

        <RadioButton

            android:id="@+id/btnMan"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="男"

            android:checked="true"/>

 

        <RadioButton

            android:id="@+id/btnWoman"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="女"/>

 

    </RadioGroup>

</LinearLayout>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值