代码之家  ›  专栏  ›  技术社区  ›  jack_the_beast

android:从path创建drop shadow

  •  0
  • jack_the_beast  · 技术社区  · 6 年前

    有没有一种方法可以创建一个具有如下路径的可绘制阴影:

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="24dp"
            android:height="24dp"
            android:viewportHeight="24.0"
            android:viewportWidth="24.0">
        <path
            android:fillColor="#FFFFFF"
            android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
    </vector>
    

    XML和编程都很好。我试着做了些调查,但什么也找不到。

    编辑:理想情况下,我需要一些可重用的向量。类似于:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            //magic happens
        </item>
        <item>
            <include> my_vector </include>
        </item>
    </layer-list>
    

    再说一次,即使是程序上也没问题,如果不是更好的话

    2 回复  |  直到 6 年前
        1
  •  1
  •   PJain    6 年前
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
        <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="24dp"
            android:height="24dp"
            android:viewportHeight="24.0"
            android:viewportWidth="24.0">
            <path
                android:fillColor="#A9A9A9"
                android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
        </vector>
    </item>
    <item>
        <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="24dp"
            android:height="24dp"
            android:viewportHeight="25.0"
            android:viewportWidth="25.0">
            <path
                android:fillColor="#ffffff"
                android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
        </vector>
    </item>
    

    请检查这个代码。

        2
  •  0
  •   Adil    6 年前

    你可以这样添加use

        <?xml version="1.0" encoding="utf-8"?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    
    <path
        android:fillColor="#ffffff"
        android:pathData="M15 12.28L20.37 18.35L17.36 21.75L12 15.68L6.64 21.75L3.63 18.35L9 12.28L3.63 6.21L6.64 2.81L12 8.88L17.36 2.81L20.37 6.21L15 12.28Z" />
    <path
        android:fillColor="#ffffff"
        android:strokeWidth="1"
        android:pathData="M15 12.28L20.37 18.35L17.36 21.75L12 15.68L6.64 21.75L3.63 18.35L9 12.28L3.63 6.21L6.64 2.81L12 8.88L17.36 2.81L20.37 6.21L15 12.28Z" />
    

    推荐文章