Android 使用drawableBottom时将文本居中

Android 使用drawableBottom时将文本居中,android,Android,我使用以下方法 我拥有的文本视图中的SetCompoundDrawableSwithinInstincBounds(null,null,null,drawable)。可绘制图形位于文本下方,但问题是它从文本开始的地方开始。有没有一种方法可以使图像上方的文本水平居中 例如,代替 Sample Text ---------------- | | | | ---------------- 是这样吗?看起来是这样的 Sample Text -

我使用以下方法

我拥有的文本视图中的SetCompoundDrawableSwithinInstincBounds(null,null,null,drawable)。可绘制图形位于文本下方,但问题是它从文本开始的地方开始。有没有一种方法可以使图像上方的文本水平居中

例如,代替

Sample Text
----------------
|              |
|              |  
----------------
是这样吗?看起来是这样的

  Sample Text
----------------
|              |
|              |  
----------------
PS:我知道我可以将布局与TextView和ImageView一起使用,并将它们对齐,但我尝试只使用TextView而不使用其本身来显示文本和图像

谢谢

试试这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableBottom="@drawable/ic_launcher"
        android:gravity="center_horizontal"
        android:text="Hello Android" />

</LinearLayout>

输出是这样的


Hmmm有趣。我会接受的。虽然我认为不建议使用负填充,但实际上,我将不得不接受这个答案,因为我尝试了,但它不起作用。它基本上截断了图像的一半,因此,您没有正确设置布局。这就是提出的问题。嘿,我现在已经编辑了答案,并附上了一个输出,请看这个。希望这对你有帮助。我感谢你的回答。我会投赞成票,但这并不能解决问题。你用这个改变了整个局面。首先我希望它是textview,其次,textview是一个wrap_内容。我想用一个文本视图来解决这个问题,我可以把它动态地放在屏幕上的任何地方