Android Constraintlayout - Align Buttons in Center And Bottom of The Screen

Sdílet
Vložit
  • čas přidán 26. 06. 2020
  • Hi and welcome to another tutorial from CodingDemos :)
    In this tutorial, you will learn how to use Android Constraintlayout to align buttons in the center and bottom of the screen.
    I did a tutorial a while back where I've shown you how to align buttons using Android Linearlayout. Here is the link: • How to Align Views at ...
    Here are the steps:
    1- Open up Android Studio.
    2- Make sure the root layout of the XML file is set to androidx.constraintlayout.widget.ConstraintLayout
    3- Add 2 Android Button. Set the label of the first button to Login while the second button to Register.
    4- Select these 2 buttons together, right-click on either one of the buttons and choose Chains and click on Create a Horizontal Chain. Android Studio will create a constrain chain for these buttons and align them in the center of the screen.
    5- Give a constraint from the top and bottom for these buttons, so that they are positioned in the center of the screen.
    6- When using Android Linearlayout there was an attribute called layout_weight which allows you to give a weight of how much space you want to assign to a button. Android Constraintlayout has a similar attribute called layout_constraintHorizontal_weight. You need to add that for these buttons and make sure you set android:layout_width="0dp".
    7- Make sure to delete this line layout_constraintHorizontal_bias from these buttons because you have added layout weight and have set the layout width to 0dp.
    8- Build and run the app to see the result.
    9- From the output, you can see the buttons are positioned in the center of the screen but you want it to be at the bottom of the screen. You can fix that by removing the constraint from the top of the buttons and the buttons will be positioned at the bottom of the screen.
    10- Now build and run the app to see the result :)
    Links:
    Android Constraintlayout: developer.android.com/trainin...
    Website: www.codingdemos.com
    FaceBook: / codingdemos

Komentáře • 16

  • @CodingDemos
    @CodingDemos  Před 4 lety +1

    Hey guys, I hope you liked this tutorial :)
    Comment below on topics you want me to cover next.

  • @cincyGary
    @cincyGary Před 3 lety

    Thanks for this video, I'm in a class using Android Studio and this is very helpful.

  • @nhloniphoshembe4934
    @nhloniphoshembe4934 Před 2 lety

    This was very helpful, thank you. :)

  • @marcelo15782
    @marcelo15782 Před 2 lety

    It helped me a lot, thank you!

  • @nandiniagarwal5943
    @nandiniagarwal5943 Před 3 lety

    Thanks a lot for this video.Helped me a lot.

  • @tejasbele1456
    @tejasbele1456 Před 3 lety

    Thank you
    That was so helpful 😁

  • @Ayushsharma-qc7qx
    @Ayushsharma-qc7qx Před 11 měsíci

    What if we have 4 buttons allgigned in row and column how to make that ui

  • @user-ic6kv7dj4x
    @user-ic6kv7dj4x Před 3 lety

    how to move them whithout android studio? iam modyfiing an app

  • @abdulwahid_mohammed
    @abdulwahid_mohammed Před 4 lety

    That seems interesting, can you make some tutorial about adding statical graphs changed by time depending on a data

    • @CodingDemos
      @CodingDemos  Před 4 lety +1

      I wrote a tutorial a while back where I show how to use a 3rd party library to draw a graph in the app, but the data was static. Here is the link: www.codingdemos.com/android-pie-chart-tutorial/

  • @mdzashimuddin7824
    @mdzashimuddin7824 Před 3 lety +1

    Bro...110% Tnx.I am really help this video...Tnx.Tnx.Tnx.Tnx.Tnx.Tnx................

  • @myworldworks
    @myworldworks Před 10 měsíci

    Thanks