Inset drawable not working as described in documentation

后端 未结 3 2023
旧巷少年郎
旧巷少年郎 2021-02-14 12:52

As described on Android Developer site:

A drawable defined in XML that insets another drawable by a specified distance. This is useful when a View

相关标签:
3条回答
  • 2021-02-14 13:14

    Another option: if you want to use DP instead of PX, try my suggestion below. From my experience, InsetDrawable only works with pixels, which I find... unhelpful. To be honest, I am not happy with this solution, but hey, it works.

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list
        xmlns:android="http://schemas.android.com/apk/res/android">
    
    <item
            android:bottom="10dp"
            android:drawable="@drawable/image_placeholder"
            android:top="10dp" />
    </layer-list>
    
    0 讨论(0)
  • 2021-02-14 13:17

    By default, setting a background drawable also applies that drawable's padding to the view. Set the padding explicitly if you don't want it to match the background drawable.

    0 讨论(0)
  • 2021-02-14 13:20

    Try to use shape with left-padding instead of inset:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
        <solid android:color="@android:color/darker_gray"/>
        <padding android:left="100dp"/>
    </shape>
    
    0 讨论(0)
提交回复
热议问题