3

I have a number of various predefined shapes (geometric, animals, plants, signs, etc.), like the one attached, but without a shadow. Images, containing these shapes, can be saved either as assets or resources.

enter image description here

Is there a way to add shadow programmatically? If the solution works only for certain image format(s) (bmp, png, svg, etc.) - I can adjust the format as required.

Asahi
  • 13,378
  • 12
  • 67
  • 87

2 Answers2

-3
android:background="@drawable/shadow"

And shadow.xml would be like

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
    android:bottom="0dp"
    android:drawable="@android:drawable/YOUR_DRAWABLE"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp">
</item>
<item
    android:bottom="0dp"
    android:left="0dp"
    android:right="0dp"
    android:top="0dp">
    <!--BackGround Color -->
    <shape android:shape="rectangle">
        <solid android:color="@android:color/red" />

    </shape>
</item>

For More Details You Can See THIS LINK

coder_baba
  • 447
  • 3
  • 21
  • 2
    wouldn't it create rectangular shadow around the entire view instead of a shadow around the shape itself? – Asahi Dec 29 '17 at 09:56
  • @Asahi Do you have limited type of drawables or want it would be dynamically? – coder_baba Dec 29 '17 at 10:01
  • @Asahi If you have certain drawables then you can customize it accordingly. else you have to find the coordinates about which you want to make shadow. – coder_baba Dec 29 '17 at 10:05
  • Number of images is going to change over time (some will be removed, new will be added). – Asahi Dec 29 '17 at 10:05
  • @Asahi I agree, Once I was also facing this problem but I had very limited drawables to i could manage only this code. – coder_baba Dec 29 '17 at 10:06
-3

another way to do it can be adding a elevation to your imageView

android:elevation="8dp"
RDO
  • 425
  • 4
  • 6