https://kotlinlang.org logo
#splitties
Title
# splitties
i

ispbox

08/08/2019, 7:48 PM
@louiscad, if I want to add some
View
into
ViewGroup
dynamically, after it's creation, is there any way to do that shorter / with Splitties DSL?
Copy code
root.addView(childView, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
All samples I've seen follow one (most common) workflow of static UI. But I need to add some views dynamically.
l

louiscad

08/08/2019, 7:50 PM
@ispbox Just use
apply
for the target
ViewGroup
, You'll then be able to work it out as when first instantiation the view hierarchy.
i

ispbox

08/08/2019, 7:57 PM
I'll just leave this sample here. Perfect solution, but not so obvious, needs some Kotlin knowledge 🙂
Copy code
root.apply {
            add(scrollView, lParams {
                width = matchParent
                height = matchParent
            })
        }
8 Views