加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml布局内容总结(二)--Android

发布时间:2020-12-16 06:13:06 所属栏目:百科 来源:网络整理
导读:关于xml中margin和padding的内容,在刚接触xml的时候会有些混淆和模糊,在此进行总结,希望能帮助到有需要的人。 2.xml中margin和padding ?xml version="1.0" encoding="utf-8"? LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" a

关于xml中margin和padding的内容,在刚接触xml的时候会有些混淆和模糊,在此进行总结,希望能帮助到有需要的人。

2.xml中margin和padding

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" //当上下左右四个方向的边距一致时,可以使用这个统一设置
android:background="@color/red"
android:orientation="vertical" >


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/yellow"
android:layout_marginLeft="5dp" //当上下左右四个方向的边距不一致时,可以分别进行设置
android:layout_marginTop="15dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="35dp"
android:orientation="vertical" >


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_margin="15dp" //这是外边框

android:padding="35dp" //这是内边框,内边框的四个方向一致时,可以统一设置
android:background="@color/blue"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray"
android:paddingLeft="5dp" //内边框的四个方向不一致时,可以分别进行设置
android:paddingTop="15dp"
android:paddingRight="25dp"
android:paddingBottom="35dp"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/green"
android:orientation="vertical" >

</LinearLayout>

</LinearLayout>

</LinearLayout>

</LinearLayout>

</LinearLayout>


效果图如下:


通过效果图和xml中的设置应该很快可以掌握margin和padding的使用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读