我正在尝试在按钮上设置左图标:
setCompoundDrawablesWithIntrinsicBounds(R.drawable.foo, 0, 0, 0);
但是该图标与按钮的左边缘和文本字符串齐平。有没有办法在提供的图标上指定一些左/右填充,使其不会正好靠在边缘?
谢谢
我正在尝试在按钮上设置左图标:
setCompoundDrawablesWithIntrinsicBounds(R.drawable.foo, 0, 0, 0);
但是该图标与按钮的左边缘和文本字符串齐平。有没有办法在提供的图标上指定一些左/右填充,使其不会正好靠在边缘?
谢谢
我相信你正在寻找的是android:drawablePadding
这是一个在按钮中使用和定位drawablePadding
图像paddingLeft
的示例paddingRight
<Button
android:id="@+id/button"
android:layout_width="200dp"
android:layout_height="80dp"
android:drawableLeft="@drawable/ic_launcher"
android:drawablePadding="2dip"
android:paddingLeft="30dip"
android:paddingRight="26dip"
android:text="Test" />
对于任何寻找程序化方式的人,这里有一个例子:
menuButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.foo, 0, 0, 0);
menuButton.setCompoundDrawablePadding(10);