如何偏移图层列表中的项目

时间:2017-09-05 23:02:54

标签: android

我的drawables中有这个图层列表文件。我想知道如何抵消覆盖在形状项上的图标。我目前将重力设置为居中,但有没有办法偏离中心?

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

    <!-- background shape -->
    <item>
        <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval" >
        <solid android:color="#ff000000"/>
        <stroke android:width="2px" android:color="#ffffffff" />
        </shape>
    </item>

    <!-- 
    icon that overlays the background shape; this icon
    has gravity set to center, but how can I change offset
    from center?
    -->
    <item
        android:drawable="@drawable/ic_wifi_on_angled"
        android:width="40dp"
        android:height="40dp"
        android:gravity="center">
        <padding android:left="100dp"/>
    </item>

</layer-list>

1 个答案:

答案 0 :(得分:0)

使用android:topandroid:bottomandroid:rightandroid:left

从右边开始2dp并且居中:

<item
    android:drawable="@drawable/action_bar_icon"
    android:width="40dp"
    android:right="2dp"
    android:height="40dp"
    android:gravity="center">
    <padding android:left="100dp"/>
</item>

enter image description here