图中 按钮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>