Android 向左填充 TextView 中的文本,其中包含左侧的图像和右侧的文本

问题描述:

我有一个 TextView,它在左侧包含一个图像,在右侧包含一个文本:

I have a TextView which contains an image on the left side and text on the right side:

我想在垂直线和文本之间创建一个空格.

I would like to create a space between the vertical line and the text.

这是我的代码:

<TextView
    android:id="@+id/locationDetailsTitleTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/map_activity_location_details_dialog_title"
    android:textColor="@color/actionbar_title_color"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:drawableLeft="@drawable/balloon_line" />

我该怎么做?

更新

这是我在balloon_line中使用的Drawable:

您是否尝试过使用 android:drawablePadding?

示例:在文本和左侧可绘制对象之间添加 5dp 的填充

Example: Adding a 5dp padding between the text and the left-side drawable

<TextView
    android:id="@+id/locationDetailsTitleTextView"
    ...
    android:drawableLeft="@drawable/balloon_line" 
    android:drawablePadding="5dp"/>