How to Programmatically Setup an Android ConstraintLayout at Runtime with ConstraintSet
Vložit
- čas přidán 7. 11. 2021
- This video is an introduction to programmatically creating a ConstraintLayout, child views, and constraints for Android using Java. Specifically, it uses the ConstraintSet convenience class to set up the constraints for a 2x2 grid of buttons that equally share the available screen space in portrait and landscape now.
Previous video showing how to set up ConstraintLayout using XML/design editor: • Introduction to Androi...
Next video showing how to do this using ConstraintLayout.LayoutParams: • How to Programmaticall...
Next video showing how to set up vertical and horizontal ConstraintLayout chains and chain styles: • How to Programmaticall...
ConstraintLayout documentation: developer.android.com/trainin... - Jak na to + styl
Thanks Grace, I wasted an hour or two dynamically trying to inflate a constraint layout and unable to figure out what's wrong. 20 minutes in and I fixed it, ty!
Thank you so much, woman
This is Gold... For someone who has custom view experience with other view groups and needs to step in to constraintlayout this is a great kickstarter.. All it needs is the magic of Kotlin and extension functions.. Loved it ❤️..
Thankyou very much
Probably the best explanation on this, and the only one that explains it all from the programming side instead of just XML. Thanks so much, please do more Android videos. This is excellent!!
I'd like to do all in one language (it gives more flexibility) and this is a very important video for the ConstraintLayout. Unfortunately, nearly no other videos explain layouts from the pure-code perspective. Thanks and well-done!
Excellent tutoriel! Merci beaucoup pour ce partage.
Today i found your channel. Your video are crisp and clear. Great job. God bless you. I noticed you have some C++ videos on your channel. Would love more content on that in the future. Thanks
this is so well explained! i was looking for a way i can load my constraint layout dynamically because i have 30 buttons with 30 corresponding textviews all to be constrained very similarly. although this still has redundant code for the buttons i was able to understand how it works and can probably come up with something for the 30 buttons now. thank you!
Thanks for the comment! For 30 buttons you can use a loop to set them up and maintain references to adjacent views for connections.
Happy coding,
-Gina
What if I want most of the layout attributes were rendered/inflate using XML file like always
except for certain element of the layout..is it possible?
Or if we want to change it dynamically for single View object we need to set the whole layout altogether in java or kotlin?
button not show in to left position
constraintSet.constrainedWidth(button1.getId(), true);
constraintSet.constrainedHeight(button1.getId(), true);
error: incompatible types: int cannot be converted to boolean
if use Constraintset.WRAP_CONTENT