I know we can set the following values to the android:gravity
and android:layout_gravity
properties:
There is many difference in the gravity
and layout-gravity
. I am going to explain my experience about these 2 concepts(All information i got due to my observation and some websites).
Use Of Gravity and Layout-gravity in
FrameLayout
.....
Note:-
Gravity is used inside the View Content as some User have answer and it is same for all ViewGroup Layout
.
Layout-gravity
is used with the parent View as some User have answer.
Gravity and Layout-gravity
is work more useful with the FrameLayout
childs . We can't use Gravity and Layout-gravity
in FrameLayout's Tag ....
We can set Child View any where in the FrameLayout
using layout-gravity
.
We can use every single value of gravity inside the FrameLayout (eg:- center_vertical
, center_horizontal
, center
,top
, etc), but it is not possible with other ViewGroup Layouts .
FrameLayout
fully working on Layout-gravity
. Example:- If you work on FrameLayout
then you don't need to change whole Layout for adding new View. You just add View as last in the FrameLayout
and give him Layout-gravity
with value.(This is adavantages of layout-gravity with FrameLayout).
have look on example ......
Output:-
Use Of Gravity and Layout-gravity in LinearLayout .....
Gravity
working same as above but here differnce is that we can use Gravity inside the LinearLayout View
and RelativeLayout View
which is not possible in FrameLayout View
.
LinearLayout with orientation vertical ....
Note:- Here we can set only 3 values of layout_gravity
that is (left
| right
| center
(also called center_horizontal
)).
have look on example :-
Output:-
LinearLayout with orientation horizontal ....
Note:- Here we can set also 3 values of layout_gravity
that is (top
| bottom
| center
(also called center_vertical
)).
have look on example :-
output:-
Note:- We can't use layout_gravity
in the RelativeLayout Views
but we can use gravity
to set RelativeLayout
childs to same position....