https://kotlinlang.org logo
#android
Title
# android
c

cypher121

11/23/2017, 3:03 AM
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

gildor

11/23/2017, 3:10 AM
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

jw

11/23/2017, 4:26 AM
100% XML
👍 3
c

cypher121

11/23/2017, 4:28 AM
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

gildor

11/23/2017, 4:42 AM
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

540grunkspin

11/23/2017, 7:16 AM
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

gildor

11/23/2017, 7:21 AM
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

540grunkspin

11/23/2017, 10:30 AM
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

cypher121

11/24/2017, 6:25 AM
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

rkeazor

11/25/2017, 6:10 PM
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