关于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的使用
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。