Image for post
Image for post

Canvas is always the best way of creating any shape of views like circles, rectangles or etc…It also can be used to crop bitmaps to your desired shapes. However, what would you do when you want to hollow out views.

In this articles, I’m gonna share few tips to hollow out views using canvas.

Let’s draw a view normally

First, this is the simplest way of drawing a black circle with Canvas in Android.

The output would be like this below.

Image for post
Image for post

Let’s hollow out a view

Finally, let’s do the thing we want to. The code below is how it will be done.

There you go.

Image for post
Image for post

Recently, I created a library called “Spotlight” using the hollowing implementation that I explained in this article. please check this out, and it would be really appreciated if you give me a star!

Enjoy hollowing out views ;)

Written by

Android Engineer at AbemaTV Github: https://github.com/takusemba

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store