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

EPG basics and animation setup

We'll start by creating a class-extending view. On its onDraw() method we will draw the following parts:

  • The view background
  • The EPG body with all the channels and TV programs
  • A top time bar hinting at the time
  • A vertical line indicating the current time

We'll also need to trigger a redraw cycle if we are animating some variables.

So, let's start with this implementation of the onDraw() method, and let's proceed method by method:

@Override protected void onDraw(Canvas canvas) { animateLogic(); long currentTime = System.currentTimeMillis(); drawBackground(canvas); drawEPGBody(canvas, currentTime, frScrollY); drawTimeBar(canvas, currentTime); drawCurrentTime(canvas, currentTime); if (missingAnimations()) invalidate(); ...

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