Performance comparison — building Android UI with code (Anko) vs XML Layout.
Andrew Drobyazko

Nice explanation, but I think you may also be forgetting about the AppCompat library and its extensive use of a custom LayoutInflater.

When an Activity inflates its views it uses a main Factory to inflate its views and a second — customizable — Factory2 can be configured to modify the way that views are inflated or even replace them. This is what happens when an AppCompatActivity inflates its views, the second Factory replaces Android standard views with AppCompat one: AppCompatButton, AppCompatEditText, AppCompatImageView…

This means that you’d have to replace all your views with AppCompat* ones manually and, as Javi Pacheco pointed out, some methods may not be as easy to use as an XML property or even not public or accessible without using reflection.

For example, while tinting an AppCompatButton may be as easy as using “app:backgroundTint=#xxxxxx”, to do the same by manually instantiating it, you would have to use “setSupportBackgroundTintList(ColorStateList)”, having to previously instantiate the ColorStateList. This may be achieved by using the “style{}” function that Anko provides, but you may be adding too much boilerplate to what should be a simple UI declaration. Another option could be extending the AppCompatViews or improving the DSL to pre-process this and make those function more user-friendly.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.