Testing the loading time of VectorDrawables vs PNGs
Switch branches/tags
Nothing to show
Clone or download
Failed to load latest commit information.
app invalid xml value removed Oct 14, 2016
gradle/wrapper empty project Oct 13, 2016
.gitignore empty project Oct 13, 2016
README.md fixing the code snippet Oct 15, 2016
build.gradle empty project Oct 13, 2016
gradle.properties empty project Oct 13, 2016
gradlew empty project Oct 13, 2016
gradlew.bat empty project Oct 13, 2016
settings.gradle empty project Oct 13, 2016


VectorDrawable vs PNG

This is a test project to check the duration of an ImageView#onDraw method when what we need to draw is a VectorDrawable or a PNG image. The app allows selecting using either a ViewDrawable or a PNG that will be displayed on the entire size of the screen and shows the draw duration on screen. The PNG and the VectorDrawable used are versions of the same SVG file.

The ImageView class is extended in the MeasurableImageView class and the onDraw method is overriden. The System.nanoTime is used to get the time before and after the onDraw of the base ImageView class.

protected void onDraw(final Canvas canvas) {
    long startTime = System.nanoTime();


    long endTime = System.nanoTime();
    notifyDraw(startTime, endTime);

The test app proves the following:

  • The 1st rendering of a VectorDrawable takes a long time. The next renderings take considerably less time.
  • The PNG is rendered in a similar amount of time at every rendering.
  • When changing the orientation, the drawing of the VectorDrawable takes longer, for the 1st rendering.