--

It matters (unless your minSdkVersion is Q or higher) because theOutline API explicitly only accepts convex paths — see the documentation. When running on P or lower, you can only pass a Path for which the isConvex property is true; if it’s false you’ll get an error (or no outline -> no shadow; I don’t recall). Starting from Q, you can also pass a concave path, but it’s unrealistic as of today to assume you can always do that given the minuscule fraction of users on Q.

In any case, you need to construct a Path that matches the vector drawable’s outline you want the shadow for, and pass it to the ViewOutlineProvider for your view. Some pseudo-code:

private fun setOutlineForDrawable() {
val myImageView: ImageView = // ...
val myVectorDrawable = myImageView.drawable
val outlinePath: Path = // ... You need to figure how to create
// this by yourself, I can't help with it
val outlineProvider = PathOutlineProvider(outlinePath)
myImageView.setOutlineProvider(outlineProvider)
}
private class NarrowerOutlineProvider(
private val path: Path
) : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
// Optional: transform path to adapt to view bounds
outline.setConvexPath(path)
}
}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sebastiano Poggi — seb@androiddev.social
Sebastiano Poggi — seb@androiddev.social

Written by Sebastiano Poggi — seb@androiddev.social

"It depends" 🤷‍♂️ - UXE on Android Studio at Google. A geek 🤓 who has a serious thing for good design ✨ and for emojis 🤟 Personal opinions only 😁

No responses yet

Write a response