Difference between gravity and layout gravity on Android

Опубликовано: 02 Апрель 2026
на канале: ID
1,003
13

Difference between gravity and layout gravity on Android

Take your app to the top keyword installs: http://bit.ly/2Xyg176

Recommended way to get genuine real and safest reviews: http://bit.ly/2XDZlpD

Recommended way to boost your apps ranking: http://bit.ly/2G3nMa7

Recommended Best Ads Mediation Network: http://bit.ly/2JpoeSl

Recommended book about the app market: https://amzn.to/2JDjojo

Subscribe To My Channel and Get More Great Tutorials
http://www.youtube.com/subscription_c...

This tutorial describes how to layout gravity on views in android, through the following steps:

1) we create a new project in an android studio with new project wizard and choose empty activity form the wizard in our project.
2) we use the existing text-view to apply gravity=center to it and we deploy that to the emulator.
3) then we remove the text-view and add three more buttons.
4) for the first button we set attribute android:gravity="top".
5) for the second button we set android:layout_gravity="right" and android:gravity="bottom" attributes.
6) for the second button we set android:layout_gravity="left" and android:gravity="center" attributes.
7) Finally we deploy and run the app to the android emulator.

Notes:

1) LinearLayout:
as the android docs describe it
a) A layout that arranges other views either horizontally in a single column or vertically in a single row.
b) To control how linear layout aligns all the views it contains, set a value for android:gravity.
c) You can set android:layout_weight on individual child views to specify how linear layout divides remaining space amongst the views it contains.

2) Gravity: described in android documentation as, Standard constants and tools for placing an object within a potentially larger container.


The source code is available for download at http://www.indragni.com/android/Andro...

►Android Developer Figurine◄
►Android Mini Collectible Figure (India): http://amzn.to/2CQRMXp
►Android Mini Collectible Figure (US): http://amzn.to/2CNO8Kk
►Android Mini Collectible Figures (India): http://amzn.to/2CRanmh
►Android Mini Collectible Figures (US): http://amzn.to/2CN6bmI

►New and Updated Android ASO Book◄
►Ultimate Guide to Android ASO: Boost android app (India): https://www.amazon.in/Ultimate-Guide-...
►Ultimate Guide to Android ASO: Boost android app (US): https://www.amazon.com/Ultimate-Guide...

►Android Developer Books◄

►For Beginners◄
►Head First Android Development (India): http://amzn.to/2CQlZpB
►Head First Android Development (US): http://amzn.to/2lNRjtC
►Android Programming for Beginners (India): http://amzn.to/2CR6dKU
►Android Programming for Beginners (US): http://amzn.to/2F8zZsg
►Mastering Android Development with Kotlin (India): http://amzn.to/2m9R8tp
►Mastering Android Development with Kotlin (US): http://amzn.to/2F5ATFX
►Learning Java by Building Android Games (India): http://amzn.to/2CRaX3r
►Learning Java by Building Android Games (US): http://amzn.to/2CYYS8W

►For Experts◄
►Expert Android Programming (India): http://amzn.to/2D4MCUD
►Expert Android Programming (US): http://amzn.to/2CXf8qV
►Android Programming: The Big Nerd Ranch Guide (India): http://amzn.to/2Fbb7Qw
►Android Programming: The Big Nerd Ranch Guide (US): http://amzn.to/2F4LbWJ
►Android Cookbook (India): http://amzn.to/2COhzys
►Android Cookbook (US): http://amzn.to/2CHSmG3
►Murach's Android Programming (India): http://amzn.to/2AB7GPL
►Murach's Android Programming (US): http://amzn.to/2F4n76a
►Mastering Android NDK (India): http://amzn.to/2CMLY0S
►Mastering Android NDK (US): http://amzn.to/2F4M3KZ
►Android High Performance Programming (India): http://amzn.to/2Fc2Vzh
►Android High Performance Programming (US): http://amzn.to/2qAruCQ
►Advanced Android Application Development (India): http://amzn.to/2D3uvhv
►Advanced Android Application Development (US): http://amzn.to/2CzoBDM

►Android Developer Gadgets◄

►USB C Cable (India): http://amzn.to/2ACjEIw
►USB C Cable (US): http://amzn.to/2F2dZ22
►Anker Micro USB to USB C Adapter (India): http://amzn.to/2F9SFrD
►Anker Micro USB to USB C Adapter (US): http://amzn.to/2CzEFFH
►Samsung Gear S3 Frontier (India): http://amzn.to/2COVfWm
►Samsung Gear S3 Frontier (US): http://amzn.to/2D1A4gL
►Sony Android Auto Media Receiver (India): http://amzn.to/2m9ripv
►Sony Android Auto Media Receiver (US): http://amzn.to/2Ef7SX9


Difference between gravity and layout gravity on Android