Draw me a rainbow: Advanced VectorDrawable rendering (Android Dev Summit '18)
Why Stack Overflow recommends it
Stack Overflow users link it when they need to draw gradients, rainbows or hatching with VectorDrawables or animate those gradients.
Recommended by 1 people across 1 different months, 2019 to 2023.
What it is
A five-minute lightning talk from Android Dev Summit 2018 in which Nick Butcher shows advanced VectorDrawable features: theme colors, stateful colors and gradients, all working back to API 14 via AndroidX. It includes a segment on repeating gradient tile modes to make rainbow-style effects.
What people said
Strong rec gmartinsnull · 2021-10 · Stack Overflow · on “Draw a Circular Rainbow Vector Drawable Android”
Might be a little late but I came across the exact same challenge and was able to pull off after watching this video [this video] (highly recommended btw). I came up with this solution was by putting searching for a vector pathData for a circular view of 21dp size, split the gradient into layers just like you did but the key was to slightly overlap the colours by repeating them back to back which creates the blurry effect from leaking the colours into the next. And lastly, I used gradient type sweep which makes them go around the given shape/path. <?xml version="1.0" encoding="utf-8"?> <vector xmlns:android=" [LINK] " xmlns:aapt=" [LINK] " android:width="21dp" android:height="21dp" android:viewpo
Cites Mehdi Haghgoo · 2019-02 · Stack Overflow · on “How to Animate A Gradient using AnimatedVectorDrawables?”
At 4:40 of Draw Me A Rainbow [this video] talk by Nick Butcher at Android Dev Summit 2018, he mentions animating a gradient. He talks about using repeat tileMode for a gradient and creating a rainbow like effect as below: gradient_one.xml: <gradient xmlns:android=" [LINK] " android:type="radial" android:startY="0" android:startX="0" android:centerX="5" android:centerY="5" android:gradientRadius="1" android:tileMode="repeat" > <item android:color="#E91E63" android:offset="0.1"/> <item android:color="#E91E63" android:offset="0.3"/> <item android:color="#3F51B5" android:offset="0.3"/> <item android:color="#3F51B5" android:offset="0.6"/> <item android:color="#03A9F4" android:offset="0.6"/> <item andr
Cites Miha_x64 · 2023-08 · Stack Overflow · on “Hatch brush style in android”
Update You can draw hatching with a gradient shader, see Draw me a rainbow: Advanced VectorDrawable rendering (Android Dev Summit '18) [this video] . Original answer To create a shader as suggested by @svdree, we need a repeatable hatching section like this: For any given line rotated by 45°, its horizontal or vertical crossing takes hypot = √(thickness² + thickness²) . Any edge contains exactly two lines, thus we need a square Bitmap of 2×hypot size. According to the picture, whiter lines come from 0, hypot/2 to hypot/2, 0 and from hypot/2, size to size, hypot/2 . To make the lines go to the end of bounds, SQUARE Cap can be used. Putting all this together, here's the code: fun Hatching45Shader(@