How to Programmatically Setup an Android ConstraintLayout at Runtime with ConstraintSet

Sdílet
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

Komentáře • 13

  • @powerlevel8000
    @powerlevel8000 Před rokem +1

    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!

  • @tehleelmir4407
    @tehleelmir4407 Před 2 lety +1

    Thank you so much, woman

  • @baranidharanmurali469
    @baranidharanmurali469 Před 2 lety +2

    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 ❤️..

  • @ayushthapamangar801
    @ayushthapamangar801 Před 2 lety

    Thankyou very much

  • @jonathan3087
    @jonathan3087 Před 2 lety

    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!!

  • @tmsngr3994
    @tmsngr3994 Před 2 lety +1

    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!

  • @naejsyned6878
    @naejsyned6878 Před 2 lety

    Excellent tutoriel! Merci beaucoup pour ce partage.

  • @gofudgeyourselves9024
    @gofudgeyourselves9024 Před 2 lety

    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

  • @mehrinfirdousi3834
    @mehrinfirdousi3834 Před 2 lety +1

    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!

    • @GinaSprint
      @GinaSprint  Před 2 lety +1

      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

  • @orangasli2943
    @orangasli2943 Před rokem

    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?

  • @j1farid867
    @j1farid867 Před rokem

    button not show in to left position

  • @j1farid867
    @j1farid867 Před rokem

    constraintSet.constrainedWidth(button1.getId(), true);
    constraintSet.constrainedHeight(button1.getId(), true);
    error: incompatible types: int cannot be converted to boolean
    if use Constraintset.WRAP_CONTENT