Android中的layout_margin和padding


图中 按钮5 为没有使用padding和layout_margin的原始按钮,其他按钮都放在一个Linearlayout中,所有控件放在一个垂直dLinearLayout中


按钮1中的文字和按钮边框之间的距离为10dp (padding)


<LinearLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:background="#aaa"
	>
	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:padding="10dp"
		android:background="#0dd"
		android:text="按钮1"
		android:textColor="#fff" />
</LinearLayout>	        


按钮2和父控件LinearLayout四边的距离为30px (layout_margin)

<LinearLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:background="#aaa"
	>		
	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:background="#00d"
		android:layout_margin="30px"
		android:text="按钮2"
		android:textColor="#fff" />
</LinearLayout>		    


按钮3和父控件LinearLayout四边的距离为40px (layout_margin),按钮3中的文字和按钮边框相距10px (padding)

<LinearLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:background="#ccc"
	android:orientation="horizontal" >

	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:background="#d00"
		android:padding="10px"
		android:layout_margin="40px"
		android:text="按钮3"
		android:textColor="#fff" />
</LinearLayout>


按钮4距离父控件LinearLayout的左边框30px,上边框15px,下边框15px  (layout_margin)  ,按钮4中的文字和按钮下边框10px,右边框20px  (padding)

<LinearLayout
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:background="#aaa"
	android:orientation="horizontal" >

	<Button
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_marginLeft="30px"
		android:layout_marginTop="15px"
		android:layout_marginBottom="25px"
		android:paddingBottom="10px"
		android:paddingRight="20px"
		android:background="#d00"
		android:text="按钮4"
		android:textColor="#fff" />
</LinearLayout>







评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值