Android:从路径创建阴影

时间:2018-12-10 11:45:11

标签: android vector drawable shadow

有没有一种方法可以给定具有以下路径的可绘制对象创建阴影:

<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 个答案:

答案 0 :(得分:0)

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

请检查此代码。

答案 1 :(得分:0)

您可以像这样添加使用

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

相关问题