是否可以为我们添加的android: drawablleft图像设置边缘或填充?


当前回答

TextView有一个android:drawablePadding属性,这应该做的伎俩:

android:drawablePadding The padding between the drawables and the text. Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type. This corresponds to the global attribute resource symbol drawablePadding.

其他回答

创建可绘制的resources.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true">
        <inset android:drawable="@drawable/small_m" android:insetLeft="10dp" android:insetTop="10dp" />
    </item>
    <item>
        <inset android:drawable="@drawable/small_p" android:insetLeft="10dp" android:insetTop="10dp" />
    </item>
</selector>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="32dp"
    android:background="@drawable/a"
    android:drawableLeft="@drawable/concern_black"
    android:gravity="center"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:drawablePadding="10dp"
    android:text="text"/>

注意:layout_width需要wrap_content,并使用paddingLeft paddingRight drawablePadding来控制间隙。如果你指定的layout_width值将有图标和文本之间的差距,我认为一旦给layout_width一个指定的值,填充将测量。

而不是按钮使用LinearLayout与ImageView和TextView里面。在子项目,如ImageView和TextView使用android:duplicateParentState="true"。

TextView有一个android:drawablePadding属性,这应该做的伎俩:

android:drawablePadding The padding between the drawables and the text. Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters). This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type. This corresponds to the global attribute resource symbol drawablePadding.

你可以使用android:drawableLeft="@drawable/your_icon"来设置drawable显示在左边。为了设置可绘制对象的填充,你应该使用android:paddingLeft或android:paddingRight分别设置左/右填充。

android:paddingRight="10dp"
android:paddingLeft="20dp"
android:drawableRight="@drawable/ic_app_manager"