android:drawableLeft 边距和/或填充 [英] android:drawableLeft margin and/or padding
问题描述
是否可以为我们使用 android:drawableLeft
添加的图像设置边距或填充?
Is it possible to set the margin or padding for the image which we added with the android:drawableLeft
?
推荐答案
正如 cephus 提到的 android:drawablePadding
只会在按钮足够小时强制在文本和可绘制对象之间填充.
As cephus mentioned android:drawablePadding
will only force padding between the text and the drawable if the button is small enough.
当布置较大的按钮时,您可以将 android:drawablePadding
与 android:paddingLeft
和 android:paddingRight
结合使用来强制文本和可向内拉向按钮的中心.通过分别调整左右内边距,您可以对布局进行非常细致的调整.
When laying out larger buttons you can use android:drawablePadding
in conjunction with android:paddingLeft
and android:paddingRight
to force the text and drawable inward towards the center of the button. By adjusting the left and right padding separately you can make very detailed adjustments to the layout.
这是一个示例按钮,它使用填充将文本和图标推得更近,而不是默认情况下:
Here's an example button that uses padding to push the text and icon closer together than they would be by default:
<Button android:text="@string/button_label"
android:id="@+id/buttonId"
android:layout_width="160dip"
android:layout_height="60dip"
android:layout_gravity="center"
android:textSize="13dip"
android:drawableLeft="@drawable/button_icon"
android:drawablePadding="2dip"
android:paddingLeft="30dip"
android:paddingRight="26dip"
android:singleLine="true"
android:gravity="center" />
这篇关于android:drawableLeft 边距和/或填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!