Saturday, 9 December 2017

What is the difference between gravity and layout_gravity in Android?

itemprop="text">

I know we can set the following values
to the android:gravity and
android:layout_gravity
properties:




  1. center

  2. center_vertical


  3. center_horizontal,
    etc.



But I am confused
regarding both of these.



What is the difference
between the usage of android:gravity and
android:layout_gravity?



Answer




Their names should help
you:





  • android:gravity
    sets the gravity of the contents (i.e. its subviews) of the
    View it's used on.

  • android:layout_gravity sets the
    gravity of the View or Layout relative
    to its parent.



And an
example is href="http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/"
rel="noreferrer">here.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...