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

Getting started with OpenGL ES in Android

It's very easy to create a 3D-enabled custom view. We can do it by simply extending GLSurfaceView instead of just extending from the View class. The complexity comes in the rendering part, but let's go step by step. First, we'll create a class named GLDrawer and add it to our project:

package com.packt.rrafols.draw; 
 
import android.content.Context; 
import android.opengl.GLSurfaceView; 
import android.util.AttributeSet; 
 
public class GLDrawer extends GLSurfaceView { 
    private GLRenderer glRenderer; 
 
    public GLDrawer(Context context, AttributeSet attributeSet) { 
        super(context, attributeSet); 
    } 
} 

Like our previous examples, we created the constructor with the AttributeSet, so we can inflate it and set parameters, ...

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