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


当前回答

@Bhargav Thanki表示:

android:drawablePadding是最简单的填充方法 可绘制图标,但你不能给特定的一侧填充像 可绘制图标的右或左填充。为了实现这个目标 必须深入调查。如果你应用左填充或右填充 到EditText,然后它将放置填充到整个EditText 与可绘制的图标。

例子:

    <TextView 
        android:layout_width="match_parent"
        android:padding="5dp"
        android:id="@+id/date"
        android:gravity="center|start"
        android:drawableEnd="@drawable/ic_calendar"
        android:background="@drawable/edit_background"
        android:hint="Not Selected"
        android:drawablePadding="10dp"
        android:paddingStart="10dp"
        android:paddingEnd="10dp"
        android:textColor="@color/black"
        android:layout_height="wrap_content"/>

其他回答

你可以为按钮使用填充,你可以使用drawablePadding

 <Button
    style="@style/botonesMenu"
    android:padding="15dp"
    android:drawablePadding="-15dp"
    android:text="@string/actualizarBD"
    android:textAlignment="gravity"
    android:gravity="center"
    android:layout_row="1"
    android:layout_column="0"
    android:drawableTop="@drawable/actualizar"
    android:id="@+id/btnActualizar"
    android:onClick="actualizarBD" />

你可以使用特定的填充取决于哪里放你的drawable,与android:paddingLeft="10dp"或android:paddingBottom="10dp"或android: paddinggright ="10dp"或android:paddingTop="10dp"

创建可绘制的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: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.

textView.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,drawable),null,null,null);

addressTitleView.setCompoundDrawablePadding();

重新制作:

<?xml version="1.0" encoding="utf-8"?>
<shape
        xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="40dp"/>

    <solid android:color="@android:color/white"/>

</shape>

to

<layer-list
        xmlns:android="http://schemas.android.com/apk/res/android">
    <item
            android:right="@dimen/_2dp"
            android:left="@dimen/_2dp"
            android:bottom="@dimen/_2dp"
            android:top="@dimen/_2dp"
            >
        <shape
                xmlns:android="http://schemas.android.com/apk/res/android">

            <corners android:radius="40dp"/>

            <solid android:color="@android:color/white"/>

        </shape>
    </item>

</layer-list>