I’m creating an `horizontalChain` in a `constraint...
# splitties
r
I’m creating an
horizontalChain
in a
constraintLayout
for the first time using the dsl, and it’s not easy nor easy to read
Note that I’m not saying I have a better solution to suggest, but the function has a lot of parameters, sometimes complex, and maybe another way to build a chain could be better
l
I agree. I think it's still better than doing it by hand (unless you are in xml using the design view of the layout editor). If you have any thoughts on it, feel free to tell them, I definitely want to improve it and your feedback can steer my imagination in a better/easier path.
r
I think it’s too complex for a single extension that does it all. I was thinking about a simple
horizontalChain
extension on
ConstraintLayout
with a parameter like
SomeCustomType.() -> Unit
, and then some extensions on
SomeCustomType
like
add(View, optional lParams)
,
var commonLParams
,
var chainStyle
, etc
Also, I ended up using a LinearLayout because the chain does not support optional views: setting the first view to GONE breaks the whole thing. I’m not sure it’s something that should work though
Maybe we could have something which would detect that the first (or last) view became GONE and apply the
firstViewParams
again on the “new” first/last view, but I think it gets too complicated. It would also require for the previous params to be remembered somewhere to be re-applied in case the previous first view becomes visible again
I at least personally expected that to work this way, but it’s because I didn’t use ContraintLayout much before I guess
l
I'm not targetting ConstraintLayout experts. I want to KISS for everyone, newbie or expert. Regarding what you wanted to do, maybe you could try to see if it works in xml (you can embed it in code with the
inflate
extension function provided in the Views DSL split itself)
r
Nah XML is not an option. What I wanted was actually a LinearLayout inside my ConstraintLayout, not just a chain. I needed more grouping. In this case I have 2 groups of 2 views, all in a line, and each of these groups can disappear. If both disappear, the whole line should disappear. It’s easier to achieve with a LinearLayout wrapper around them, at least for me.
l
Ah, yes, LinearLayout is easier for that. I recently experienced the same when trying to do clever constraints that ended up with an ugly result and had a hard time managing the visibility of the whole column vs the visibility of a specific view without having those clash.
Why is xml not an option for you? Curious 🙂
r
XML was not meant to be written by humans, and for me it’s in the same spot than PHP and raw JS: don’t use it
l
Of course, but the layout editor is meant to write it for you. I agree with you nevertheless, and that's why I made and maintain Splitties Views DSL
r
The last time I used it, the layout editor was very bad in IDEA, but it was a long time ago.