如何在图层列表中对项目进行偏移

4

我有一个图层列表文件在我的可绘制资源中。我想知道如何偏移覆盖在形状项上的图标。我目前将重力设置为中心,但是否有一种从中心偏移的方法?

<?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个回答

1
使用 android:top, android:bottom, android:right 或者 android: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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接