With the tool HierarchyViewer you are able to inspect the layout hierachies of your app. That works fine and I have no problems to analyse my views. I also checked my sourced with Lint.
As described in Optimizing Your UI the colors represent the speed of how fast the view can be measured, layouted and drawn.
Performance indicators: A set of three colored dots that indicate the rendering speed of this View relative to other View objects in the tree. The three dots represent (from left to right) the measure, layout, and draw times of the rendering:
The colors indicate the following relative performance:
- Green: For this part of the render time, this View is in the faster 50% of all the View objects in the tree. For example, a green dot for the measure time means that this View has a faster measure time than 50% of the View objects in the tree.
- Yellow: For this part of the render time, this View is in the slower 50% of all the View objects in the tree. For example, a yellow dot for the layout time means that this View has a slower layout time than 50% of the View objects in the tree.
- Red: For this part of the render time, this View is the slowest one in the tree. For example, a red dot for the draw time means that this View takes the most time to draw of all the View objects in the tree.
That means that a a red bulb "only" means that the particular item is the slowest one in comparison to all other items in the tree. It does not mean the time is slower then value X and because of that it's read - like you know it from lets say ping analysing tools which display their result in a traffic light manner for "slow, middle, fast" regarding to the measured ping times.
After inspecting different views of my application I noticed that input fields are slower then text fields, LinearLayouts
are faster then FragmentLayouts
and some stuff like this. I then searched for information and help about improving the draw time of some of my views.
But that search was not very satisfactory to me.
Googles Optimizing Your UI tells you this:
Optimizing with View Hierarchy
View Hierarchy also helps you identify slow render performance. You start by looking at the View nodes with red or yellow performance indicators to identify the slower View objects. As you step through your application, you can judge if a View is consistently slow or slow only in certain circumstances.
Remember that slow performance is not necessarily evidence of a problem, especially for ViewGroup objects. View objects that have more children and more complex View objects render more slowly.
The View Hierarchy window also helps you find performance issues. Just by looking at the performance indicators (the dots) for each View node, you can see which View objects are the slowest to measure, layout, and draw. From that, you can quickly identify the problems you should look at first.
What tells you more or less nothing in my option. On another page Revise Your Layout there is a little example where two text views inside a LinearLayout
and put inside a RelativeLayout
so that one hierachy is gone.
Some more tips are found in the Use Lint section:
- Use compound drawables - A LinearLayout which contains an ImageView and a TextView can be more efficiently handled as a compound drawable.
- Merge root frame - If a FrameLayout is the root of a layout and does not provide background or padding etc, it can be replaced with a merge tag which is slightly more efficient.
- Useless leaf - A layout that has no children or no background can often be removed (since it is invisible) for a flatter and more efficient layout hierarchy.
- Useless parent - A layout with children that has no siblings, is not a ScrollView or a root layout, and does not have a background, can be removed and have its children moved directly into the parent for a flatter and more efficient layout hierarchy.
- Deep layouts - Layouts with too much nesting are bad for performance. Consider using flatter layouts such as RelativeLayout or GridLayout to improve performance. The default maximum depth is 10.
But what I still miss are some (proofed) answers and tips how to design good view hierachies or which view elementes should not (heavily) be used / combined with outher elements. Something like you should sparley use layout_weight
as it can slow down performance (Revise Your Layout).
In the lint analysed there are some helpfull phrased like
Set android:baselineAligned="false" on this element for better performance
So my question is now: What tips / hints / "code styles" do you know to improve the performance of your UI? What view elements should be used instead of others as they perform better? What do you do to improve layout performances?