0

这里有一个简单的问题:我正在自定义一些按钮,通过 android:drawableLeft 或 Right 在我的文本旁边放置一个图标,但我似乎无法找到如何准确地定义大小。我的图像恰好太大,超出了按钮的形状。

哦,当我在它的时候: android:drawableLeft 允许将图像放在文本的左侧,但是如何确定与文本的距离?就我而言,当我的文本居中时,它会自动转到按钮的最左侧。结果是一切都很好!

谢谢 !

4

3 回答 3

1

如果你想定义drawable的精度大小,你应该使用Java代码而不是android:drawableLeft

  Drawable dw = getResources().getDrawable(R.drawable.ic);
  dw.setBounds(0, 0, 100, 100); // set the size of the drawable to 100*100

  button.setCompoundDrawables(dw, null, null, null);

因为

 android:drawableLeft // equals with  setCompoundDrawablesWithIntrinsicBounds

 android:drawablePadding // this used to control the padding between the text and drawable
于 2013-04-09T09:04:48.803 回答
1

我建议从这个话题开始。

但是如何确定与文本的距离?

在这里你有一个答案:

android:drawablePadding 可用于指定图像和按钮文本之间的填充量。

资源

于 2013-04-09T08:24:47.900 回答
1

我想这会成功的

android:drawablePadding结合使用并android:paddingLeft强制android:paddingRight文本和drawable向内朝向按钮的中心......

于 2013-04-09T08:29:05.973 回答