Android Constraintlayout - Align Buttons in Center And Bottom of The Screen
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
Hey guys, I hope you liked this tutorial :)
Comment below on topics you want me to cover next.
Thanks for this video, I'm in a class using Android Studio and this is very helpful.
This was very helpful, thank you. :)
It helped me a lot, thank you!
Thanks a lot for this video.Helped me a lot.
You're welcome 😃
Thank you
That was so helpful 😁
You're welcome 😃
What if we have 4 buttons allgigned in row and column how to make that ui
how to move them whithout android studio? iam modyfiing an app
That seems interesting, can you make some tutorial about adding statical graphs changed by time depending on a data
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/
Bro...110% Tnx.I am really help this video...Tnx.Tnx.Tnx.Tnx.Tnx.Tnx................
You're welcome 😃
Thanks
You're welcome 😃