Android Development

Guowei Lv

5 minute read

In this post we talk about the drawing order in custom view. After super.onDraw() What we have done in the previous episodes is to override the onDraw() method of the View class. A lot of times we do not need to create our own custom view from scratch. We can simply extends an existing view, e.g. ImageView. If we want to draw something on top of the image, we can write that after the super.

Instance Initialization Block in Android

Use of IIB block in Android

Guowei Lv

2 minute read

This will be a short and sweet post. The usage of Instance Initialization Block of Java in custom android views. First of all, I have a confession to make. After almost 10 years of Java programming, I do not really know what is IIB and why it exists. Pretty obviously, the purpose of IIB is to initialize instance variables of a class. But you may ask isn’t that the job of constructors?

Android Custom View 102 (Part III)

Geometric Transformations

Guowei Lv

7 minute read

In this post, we will be focusing on what canvas can do. To demonstrate the effects, I simply created custom view that draws an image. The original verion is like this: Clip Clipping is easy to understand, it’s like cut the view in a certain way so that only part of it is shown. There are 2 methods: clipRect() and clipPath(). clipRect() This method will clip the view using a rectangle.

Guowei Lv

11 minute read

Android custom view

In this post, we will be focusing on the Paint. Color The color in Paint has 3 parts: basic color, color filter and xfermode. Basic color There are 2 ways to set color in Paint: use setColor() and use Shader. Set color directly Two methods can be used: paint.setColor(Color.parseColor("#B90E83"); paint.setARGB(100, 255, 0, 0); There is no difference, pick whichever you like. Set color using Shader There are different types of Shader, let’s look them one by one.

Android Custom View 102 (Part I)

The basics of drawing stuff

Guowei Lv

4 minute read

Android custom view

If 101 is like a crash course, then this 102 will provide much more detail. In this 1st part, we focus on only one thing: how to draw things. Draw Color Draw the entire view with one color. public class DrawColorView extends View { … @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.YELLOW); } } Draw Circle Draw a circle on the view. Pay attention that all drawXXX() functions use pixel as unit.