android:layout_marginLeft指该控件距离边父控件的边距, android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

本文详细解释了Android中layout_marginLeft和paddingLeft两个属性的区别及应用。layout_marginLeft用于定义控件与父控件间的水平间距;paddingLeft则用于定义控件内部内容与控件边界的间距。通过实例说明了这两个属性在实际UI设计中的不同效果。



android:layout_marginLeft指该控件距离边父控件的边距,

android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

 

如:

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px":

按钮上设置的内容(例如图片)离按钮左边边界30个像素。

android:layout_marginLeft="30px"

整个按钮离左边设置的内容30个像素

这二个属性是相对的,假设B是A的子控件,设置B的margin和设置A的padding能达到相同的效果。

android:layout_marginLeft指该控件距离边父控件的边距,

android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

 

如:

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px":

按钮上设置的内容(例如图片)离按钮左边边界30个像素。

android:layout_marginLeft="30px"

整个按钮离左边设置的内容30个像素

这二个属性是相对的,假设B是A的子控件,设置B的margin和设置A的padding能达到相同的效果。




android:layout_marginLeft指该控件距离边父控件的边距,

android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

 

如:

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px":

按钮上设置的内容(例如图片)离按钮左边边界30个像素。

android:layout_marginLeft="30px"

整个按钮离左边设置的内容30个像素

这二个属性是相对的,假设B是A的子控件,设置B的margin和设置A的padding能达到相同的效果。



android:layout_marginLeft指该控件距离边父控件的边距,

android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

 

如:

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px":

按钮上设置的内容(例如图片)离按钮左边边界30个像素。

android:layout_marginLeft="30px"

整个按钮离左边设置的内容30个像素

这二个属性是相对的,假设B是A的子控件,设置B的margin和设置A的padding能达到相同的效果。

android:layout_marginLeft指该控件距离边父控件的边距,

android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

 

如:

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px":

按钮上设置的内容(例如图片)离按钮左边边界30个像素。

android:layout_marginLeft="30px"

整个按钮离左边设置的内容30个像素

这二个属性是相对的,假设B是A的子控件,设置B的margin和设置A的padding能达到相同的效果。

android:layout_marginLeft指该控件距离边父控件的边距,

android:paddingLeft指该控件内部内容,如文本距离该控件的边距。

 

如:

当按钮分别设置以上两个属性时,得到的效果是不一样的。

android:paddingLeft="30px":

按钮上设置的内容(例如图片)离按钮左边边界30个像素。

android:layout_marginLeft="30px"

整个按钮离左边设置的内容30个像素

这二个属性是相对的,假设B是A的子控件,设置B的margin和设置A的padding能达到相同的效果。

<?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"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:id="@+id/控件1" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginleft="10dp" android:textSize="24sp" android:text="控件1" /> <TextView android:id="@+id/控件2" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" android:layout_marginleft="10dp" android:text="控件2" /> <TextView android:id="@+id/控件3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="控件3" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:id="@+id/控件4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:textSize="24sp" android:text="控件4" /> <TextView android:id="@+id/控件5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="控件5" /> <TextView android:id="@+id/控件6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:textSize="24sp" android:text="控件6" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp"> <TextView android:id="@+id/控件7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:textSize="24sp" android:text="控件7" /> <TextView android:id="@+id/控件8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:textSize="24sp" android:text="控件8" /> <TextView android:id="@+id/控件9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:textSize="24sp" android:text="控件9" /> </LinearLayout> </LinearLayout>重新帮我改
最新发布
10-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值