Learn to recreate the Matrix Effect on Android

Also known as Digital Rain Effect, the Matrix Effect is a classic effect featured in the Matrix series films. A green code is falling and represents the activity of the virtual reality environment of the Matrix on screen. On Android, Matrix Effect has been implemented in various applications often as a Live Wallpaper. In that tutorial, you are going to learn how to create a simple Matrix Effect.

You can discover this tutorial directly in video on Youtube :

Even better, you can enjoy the Matrix Effect as an Android Live Wallpaper application just here on the Google Play Store :

  1. Create a Matrix Effect custom View

First, you need to create a custom view named MatrixEffect :

First, we define the variables for the Matrix Effect with the size of the code, the size of a column, the position of the bottom text for each column and then the caracters that will be used for the code. Note that you can put the caracters you want here or why not a custom font.

In the constructor, we initialize the paint objects. To get view width and height, we override the onSizeChanged method of the View. We initialize the position of the first caracter for each column. We use a random position between the top of the screen and the middle of the screen.

Then, we define a draw text method used to draw a random caracter for each column at the position indicated by txtPosByColumn variable.

The drawCanvas method is used to draw the background of our view and then the code.

Finally, we override the onDraw method of our custom view to call the drawCanvas method and invalidate the view to force a redraw. With that call, the Matrix Effect could progress from top to bottom in infinite mode. Note that it is not the most optimized way to manage a Matrix Effect, but for a tutorial it’s sufficient.

2. Define the MatrixEffect View on the Layout

Now, we can define the MatrixEffect View on the layout of the Main Activity.

3. Set the layout on the Main Activity

Last step is to set the layout as content view for the Main Activity.

4. Demo

To enjoy the Matrix Effect, you have just to launch the application on an Android device and you should see the following effect :

To discover more tutorials on Android development, don’t hesitate to visit the SSaurel’s Channel on YouTube : https://www.youtube.com/user/sylsau/

If you have ideas for new tutorials, don’t hesitate to tell me in comments.

Entrepreneur / Developer / Blogger / Author. In Bitcoin We Trust: https://www.inbitcoinwetrust.net

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store