Shadow drawing can be used using "layer-list"
Background
I am trying to make a (fake) shadow below the view so that the layers will be vertical this way:
- color string "# 43000000" with height "1dp"
- below the line, the gradient starting at the vertex with the color "# 1A000000" and ending with the color "# 00000000" and having a height of "8dp".
Problem
For some reason, I cannot draw the line correctly.
No matter what I do, the line takes up all the space for some reason, while the gradient seems fine.
What i tried
I've tried using "line" as shape as well as "rectangle". I also tried using "stroke" instead of "solid", tried adding padding and margins ...
Here's the XML of the extracted file:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<size android:height="1dp" />
<solid android:color="#43000000" />
</shape>
</item>
<item android:top="1dp">
<shape android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#00000000"
android:startColor="#1A000000" />
<size android:height="8dp" />
</shape>
</item>
</layer-list>
Again, this isn't the only one I've tried. This is my first try.
Question
How can I fix this XML? what is causing this?
+3
source to share
2 answers
Here's what I found to work:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="8dp">
<shape android:shape="rectangle" >
<size android:height="1dp" />
<solid android:color="#43000000" />
</shape>
</item>
<item android:top="1dp">
<shape
android:dither="true"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#00000000"
android:startColor="#10000000" />
<size android:height="8dp" />
</shape>
</item>
</layer-list>
+7
source to share
Tried with this, can it satisfy your needs with a gradient
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#e040fb"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#E1BEE7"/>
<corners android:radius="2dp" />
<gradient
android:angle="270"
android:endColor="#e1bee7"
android:startColor="#e040fb" />
</shape>
</item>
</layer-list>
0
source to share