• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Rule: InefficientWeight
2//
3// Description: Checks whether a layout_weight is declared inefficiently.
4//
5// Conditions:
6// - The node has a LinearLayout parent
7// - The node is the only sibling with a weight
8// - The node has a height/width != 0
9
10def parent = node.'..'
11if (parent.is("LinearLayout") && node.'@android:layout_weight' &&
12        parent.'*'.findAll{ it.'@android:layout_weight' }.size() == 1) {
13    def dimension = parent.'@android:orientation' == "vertical" ?
14        "android:layout_height" : "android:layout_width"
15    if (node."@${dimension}"[0] != '0') {
16        analysis << "Use an ${dimension} of 0dip instead of ${node."@${dimension}"} " +
17                "for better performance"
18    }
19}
20