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

Transformations and operations

We already used some canvas transformations on our custom view before, but let's revisit the Canvas operations we can use. First of all, let's see how we can concatenate these transformations. Once we've used a transformation, any other transformation we use will be concatenated or applied on top of our previous operations. To avoid this behavior, we've to call the save() and restore() methods we also used before. To see how transformations build on top of each other, let's create a simple example.

First, let's create a paint object on our constructor:

 

public PrimitiveDrawer(Context context, AttributeSet attributeSet) { super(context, attributeSet); paint = new Paint(); paint.setStyle(Paint.Style.STROKE); ...

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