是否可以为我们添加的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"/>

其他回答

重新制作:

<?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>

是的。使用drawablePadding,如下所示

<TextView
        android:id="@+id/tvHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Settings and Contents"
        android:drawableLeft="@drawable/icon_success"
        android:drawablePadding="10dp" />

另一个简单的解决方案可以通过嵌入layerlist实现

layered_drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <inset
            android:insetRight="30dp"
            android:drawable="@drawable/ic_air_date">
        </inset>
    </item>
</layer-list>

XML中的按钮

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/layered_drawable"
    android:text="something" />
textView.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,drawable),null,null,null);

addressTitleView.setCompoundDrawablePadding();

尝试使用负填充

如:

android:paddingLeft="-8dp"