Hi,

Well, first of all RelativeLayout ignores layout_gravity. Then you
need to know that gravity means "apply gravity to the content of this
view" whereas layout_gravity means "apply gravity to this view within
its parent." So on a TextView, gravity will align the text within the
bounds of the TextView whereas layout_gravity will align the TextView
within the bounds of its parent.

On Thu, May 14, 2009 at 5:31 AM, Matthias <m.kaepp...@googlemail.com> wrote:
>
> Hi,
>
> I think I've lost enough hair over this, so now I'll ask. What is the
> difference between those attributes? According to the documentation of
> R.attr, there isn't any difference (doc text is exactly the same, see
> http://developer.android.com/reference/android/R.attr.html), but
> apparently, that's simply not true. For example, the gravity attribute
> can be used on EditText to set the text alignment (e.g. left, center,
> right).
>
> I often found that neither of them work to align a view at all. For
> example, I need to float two text views in a relative layout, one
> going to the left below a title bar, the other going to the right
> below the title bar. So what I did was this:
>
> <RelativeLayout
>    xmlns:android="http://schemas.android.com/apk/res/android";
>    android:layout_width="fill_parent"
>    android:layout_height="fill_parent">
>
>    <!-- the title bar -->
>    <ImageView ...
>    </ImageView>
>
>    <TextView android:id="@+id/left_text"
>        android:layout_below="@id/title_bar"
>        android:layout_gravity="left"
>        ...
>        />
>
>    <TextView android:id="@+id/right_text"
>        android:layout_below="@id/title_bar"
>        android:layout_gravity="right"
>        ...
>        />
>
> </RelativeLayout>
>
> That doesn't work, however. The left text is indeed aligned to the
> left inside its parent (the relative layout), but the right text is
> not aligned to the right; instead, it's placed directly to the right
> of the left text.
>
> Why's that?
>
> Thanks,
> Matthias
>
> >
>



-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to