11/28/2016, 10:35 PM
@joe_androidsecurity Well ideally the preview would work, and you wouldn’t just do everything twice. Let’s assume the preview does work: 1) You now have a much nicer syntax to declare you’re views in; xml just gets clunky and very verbose, I end up writing the same parts of the view many times 2) Everything is in kotlin, so you can do anything else you could do while inside of an activity etc. You get instant databinding without needing to do any of the standard android binder stuff 3) The way android builds views that were written in xml, it does so via reflection, Reflection is notoriously slow and having reflection in the view building process will most likely be a bottleneck. 4) The alternative to building views in XML, is to do it programmatically using java (Which is by far, much faster), however to do so is a giant pain in the ass with tons of boilerplate. Anko provides, frankly, a really easy to use DSL to help you build programmatically 5) So overall, the speed of building layouts at runtime, plus the ease of writing the views (which is easier than the xml) plus all the functionality of having a reference to your view object + all the java/kotlin stuff you can do to your views is a huge benefit. I personally use MVVM, where my viewmodels expose observables, which was really easy to integrate with my anko views. To do so with xml views involved me wiritng custom binding adapters for pretty much every data type I would need to have a binding for.
💯 3