Drawing operations
As we've just mentioned, we have already seen and used some drawing operations, but that was only the envelope of what's inside. We'll see new drawing operations and how to combine them.
Bitmaps
Let's start by drawing bitmaps or images. Instead of having a white background, we'll use an image as background for our custom view. Using the source code from our previous example, we could do some very simple modifications to draw an image:
First, let's define a Bitmap
object that will hold a reference to the image:
private Bitmap backgroundBitmap;
To start, let's initialize it with the application icon we already have on our application:
public CircularActivityIndicator(Context context, AttributeSet attributeSet) { super(context, attributeSet); backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
BitmapFactory
provides us several ways to load and decode images.
Once we have the image loaded, we can draw it on our onDraw()
method...