Android layout optimization papers

First, the use of labels

include: label layout sharing

ViewStub: Label delay loading implement, which is not visible, and size of the view 0, when it is set to be visible or inflate after layout will fill resources.

merge: the label layout to reduce the level

Second, try to use CompoundDrawable

比如:android:drawableBottom="@mipmap/ic_launcher"

Third, the use Lint

Android Lint addition to checking can be static Java code can also be used to check the application's layout can be optimized for the existence of. Lint following rules are set up specifically to optimize the layout:

  • AndroidLintUseCompoundDrawables : it is to try to use CompoundDrawable described earlier.
  • MergeRootFrame : merge tag is described previously to reduce the layout level.
  • TooManyViews : there are too many single layout View, by default, the layout of a single View can only be the number 80, may be considered to reduce the number of used CompoundDrawables like a View.
  • TooDeepLayout : avoid excessive layout nesting, by default, the layout of a single level up 10, may be considered to reduce the level of use RelativeLayout layout.
  • UselessParent : extra parent control.
  • NestedWeights : android: layout_weight View property will be measured twice, when a non-LinearLayout have 0dp worth android: layout_weight property, which is outside the nest again if there is a non-0dp LinearLayout, the measure of control increases exponentially.
  • UselessLeaf : no children layout View, did not set the background, it should be removed.
  • InefficientWeight : When only one child View LinearLayout defined android: layout_weight properties, higher performance approach is to use a 0dp android: layout_height or android: layout_width to replace it, so that it is necessary to measure the child View corresponding to its own size.

 

"Android Advanced Advanced"

Published 49 original articles · won praise 2 · Views 8580

Guess you like

Origin blog.csdn.net/yangjunjin/article/details/105163396