aboutsummaryrefslogtreecommitdiffstats
path: root/layoutopt/libs/uix/src/resources/rules/InefficientWeight.rule
blob: ea93b1bb9be08b87563bcd953fc57386d57d0ffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Rule: InefficientWeight
//
// Description: Checks whether a layout_weight is declared inefficiently.
//
// Conditions:
// - The node has a LinearLayout parent
// - The node is the only sibling with a weight
// - The node has a height/width != 0

def parent = xml.'..'
if (parent.is("LinearLayout") && xml.'@android:layout_weight' &&
        parent.'*'.findAll{ it.'@android:layout_weight' }.size() == 1) {
    def dimension = parent.'@android:orientation' == "vertical" ?
        "android:layout_height" : "android:layout_width"
    if (xml."@${dimension}"[0] != 0) {
        analysis << [node: node, description: "Use an ${dimension} of 0dip instead of " +
                "${xml."@${dimension}"} for better performance"]
    }
}