I recently wrote an article explaining how to track down and fix performance issues in Android application. This article was by no means a complete reference on how to solve all performance issues and focused on a particular set of issues caused by overdraw.
To help you better understand how to fix overdraw issues, I would like to invite you to download a small Android application I wrote (click File > Download to download the entire archieve.)
Your goal will be to use the tools described in my previous article to find and fix the 3 main overdraw issues in the app. If you do it right, you should turn the image on the left to the image on the right:
Thanks for the previous post, and the practical training !
I guess the most tricky part is to cut out the nine-patch drawable ;)
I have a question. Our team used to strictly obey the Lint warnings. The recent Lint enhancements are awesome.
For your project, the lint warning reported as below for the file activity_main.xml
Possible overdraw: Root element paints background @color/dark_background with a theme that also paints a background (inferred theme is @style/AppTheme)
Going by the above suggestion we achieved the right side image. Now my question(confused), for finding the overdraw which one you suggest?? Lint or the debug methodology you suggested.
[...] Afin de vous entrainer à éviter l’effet d’overdraw (redessiner plusieurs fois un composant inutilement), Romain Guy propose un projet d’exemple. [...]
Hmm…after I finished fixing the 9-patch and set background drawable to null, my ActionBar background had no colour and the text + icon were blue, instead of green. :)
Thanks for this exercise Romain
is anyone else having a problem with “getWindow().setBackgroundDrawable(null);” having no effect to the overdraw? It works fine when it’s in the theme but not programmatically in onCreate()
Any response to the problem reported about setting windowbackground to @null causing “smearing”? See: http://stackoverflow.com/questions/12150761
Afraid to try it because of that bug report.
could you talk about building custom list view from scratch with a high performance
could you talk about building custom list view from scratch with a high performance
@Josh, I didn’t have a problem with that.
@Afzal/Anyone, hmmm. I see no difference at all. Do you? getWindow().setBackgroundDrawable(null) seems to have has no affect on overdraw. Sample is below.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(null);
setContentView(R.layout.main);
}
and main.xml is just 2 view containers.
WP is stripping out the xml… the xml for main.xml is just 2 containers both have a background color. The inner once has 20 dp padding on the left and right so you can see the overdraw layers.
Call setBackgroundDrawable(null) after setContentView() and see if it helps.
[...] is a really good explanation how can you optimize your UI so it can load faster : Android Performance in Practice by Romain Guy. I suggest you to take a [...]
Will there be a solution published?
replace @drawable/frame to @drawable/frame_hole in layout/photo_item.xml will do most of the work.