O'Reilly logo

Building Android UIs with Custom Views by Raimon Ràfols Montané

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing more primitives

Let's start by the simplest drawing operations: drawColor(int color), drawARGB(int a, int r, int g, int b), drawRGB(int r, int g, int b), and drawPaint(Paint paint). These will fill the entire canvas, taking into account the clipping area.

Let's move forward to drawRect() and drawRoundRect(). These two methods are quite simple too, drawRect() will draw a rectangle and drawRoundRect() will draw a rectangle with rounded borders.

We can use both methods directly, specifying the coordinates or using Rect. Let's create a simple example that will draw a new random rounded rectangle every time the view is drawn or it’s onDraw() method is called.

To start, lets define two ArrayLists; one will hold the coordinates and the other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required