I was wondering, how much do you guys use XML in c...
# android
c
I was wondering, how much do you guys use XML in code? I'm still learning, so I'm not sure if it's better kept to a minimum with help of libraries like anko
g
We use databinding library, so all layouts are xml. Many people still like XML for layouts even without bindings
👍 1
Also, new layout builder that supports Constraint Layouts for example works only with XML. There is a plugin to enable preview for Anko, but it’s impossible for builder
👍 1
j
100% XML
👍 3
c
so databinding doesn't work with code layouts well? Most of my UI experience is on JavaFX, so I'm kinda used to property binding, which works just fine with code
g
databinding doesn’t work with code layouts well
Android Data Binding uses XML to bind views to viewmodel properties and actually that’s the main purpose of bindings, avoid write view interaction code, but just bind viewmodel to xml layout You can write some adapter to use databinding api with code views of course, but not sure that it make a lot of sense. Maybe easier to write some lib that uses own extensions for views to bind properties using rx or something like that
u
I would go with XML and databindings especially since constraint layout. You can even write your own two way databindings and this keeps the code in the activity really low so basically your activity/fragment just becomes a main method with glue code. Really recommend this article of you want to learn more about data binding adapters: https://medium.com/google-developers/android-data-binding-2-way-your-way-ccac20f6313
What you will still need in the activity is handling of navigation and notifications (dialog and snackbars)
g
You can provide dialog/navigation/notification presenters to ViewModel to reduce ammount of code that you do in activity, for example it’s useful to handle dialog responses in ViewModel, you just need wrapper for dialogs
u
Sure this works when you don’t use the ViewModel in architecture components since the ViewModel class should not have any references to an activity
But maybe there is a good way to get around this? Uf so I would be endlessly thankful
c
so from what I get, 2 main downsides is that anko does not keep up with new layouts and you need to do your own databinding, right?
r
XML all the way. I actually think xml is cleaner. Anko has a bit to much nesting for my taste lol. Plus Databinding and the design tool have came along way