Eric Holk | c4239ac | 2018-09-05 10:43:31 -0700 | [diff] [blame] | 1 | # View Compiler |
| 2 | |
| 3 | This directory contains an experimental compiler for layout files. |
| 4 | |
| 5 | It will take a layout XML file and produce a CompiledLayout.java file with a |
| 6 | specialized layout inflation function. |
| 7 | |
| 8 | To use it, let's assume you had a layout in `my_layout.xml` and your app was in |
| 9 | the Java language package `com.example.myapp`. Run the following command: |
| 10 | |
| 11 | viewcompiler my_layout.xml --package com.example.myapp --out CompiledView.java |
| 12 | |
| 13 | This will produce a `CompiledView.java`, which can then be compiled into your |
| 14 | Android app. Then to use it, in places where you would have inflated |
| 15 | `R.layouts.my_layout`, instead call `CompiledView.inflate`. |
| 16 | |
| 17 | Precompiling views like this generally improves the time needed to inflate them. |
| 18 | |
| 19 | This tool is still in its early stages and has a number of limitations. |
| 20 | * Currently only one layout can be compiled at a time. |
| 21 | * `merge` and `include` nodes are not supported. |
| 22 | * View compilation is a manual process that requires code changes in the |
| 23 | application. |
| 24 | * This only works for apps that do not use a custom layout inflater. |
| 25 | * Other limitations yet to be discovered. |