This presentation explains in detail some of the performance improvements provided by Android 4.4. You will also learn about tools and tips you can use to improve performance of your applications.
targetSdkVersion must be >= 19 • Views cache measured dimensions - Prior to 4.4 only the last measure was cached - In 4.4 all measures are cached until next requestLayout() • Can greatly reduce calls to onMeasure()
opaque elements • Avoids drawing them • Eliminates some common overdraw situations • But you should still avoid it in your apps Overdraw Window Background 1x
opaque elements • Avoids drawing them • Eliminates some common overdraw situations • But you should still avoid it in your apps Overdraw Container Background 2x
opaque elements • Avoids drawing them • Eliminates some common overdraw situations • But you should still avoid it in your apps Overdraw Button Button 2.1x Views
opaque elements • Avoids drawing them • Eliminates some common overdraw situations • But you should still avoid it in your apps Overdraw Window Background 0x
opaque elements • Avoids drawing them • Eliminates some common overdraw situations • But you should still avoid it in your apps Overdraw Container Background 1x
opaque elements • Avoids drawing them • Eliminates some common overdraw situations • But you should still avoid it in your apps Overdraw Button Button 1.1x Views
etc… - Also called “sprite sheets“ • Can increase performance - Reduce number of OpenGL driver calls - Reduce number of GPU state changes - Better merging of draw calls
final int count = mEntries.size(); for (int i = 0; i < count; i++) { Entry entry = mEntries.get(i); int x = computeX(entry); int y = computeY(entry); mDst.set(x, y, x + entry.src.width(), y + entry.src.height()); canvas.drawBitmap(mAtlas, entry.src, mDst, null); } }
final int count = mEntries.size(); for (int i = 0; i < count; i++) { Entry entry = mEntries.get(i); int x = computeX(entry); int y = computeY(entry); mDst.set(x, y, x + entry.src.width(), y + entry.src.height()); canvas.drawBitmap(mAtlas, entry.src, mDst, null); } }
final int count = mEntries.size(); for (int i = 0; i < count; i++) { Entry entry = mEntries.get(i); int x = computeX(entry); int y = computeY(entry); mDst.set(x, y, x + entry.src.width(), y + entry.src.height()); canvas.drawBitmap(mAtlas, entry.src, mDst, null); } }
entries - Allows proper bilinear filtering - For scaling, rotation, perspective, etc. • Watch out for max texture size - Especially at xxhdpi - 2048x2048 is common - 4096x4096 on recent devices
entries • Use a Paint with the SRC blend mode - mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)) • Store this information in atlas file - Name,left,top,right,bottom,1 // 1=opaque, 0= transparent
height to 0dp for children with a weight • Horizontal layouts - Set width to 0dp for children with a weight - And set baselineAligned=”false” on LinearLayout • These tips don’t always apply
Keep the jellybeans canvas.clipRect(l, t, r, b); // Rotate the jar canvas.rotate(-30.0f, pX, pY); // Draw the jar canvas.drawBitmap(mJellyBeans, x, y, null); }