Guys, thanks for clearing up! I'll file a bug against the documentation then, because there it says:
"public static final int gravity Specifies how to place an object, both its x and y axis, within a larger containing object." Which is true for layout_gravity, but not gravity. Apart from that, I solved my problem by wrapping the two TextViewS in a horizontal LinearLayout and setting the left text to have a larger weight than the right text, so that it pushes the right text to the edge of the container (which is a good solution for me, because the left text has dynamic length, while the right one is fixed). I suspected this would work, but I first refused to try it, because somewhere in the docs or on Romain's blog it was mentioned that using LinearLayoutS and weights would be more expensive than using e.g. a RelativeLayout, because of additional layout measurement cycles. It would be great though if things like these (i.e. that RelativeLayout ignores layout_gravity) would appear somewhere in the documentation. It's not immediately apparent to people why for some layouts the gravity is simply ignored, and for others it's not. Anyway, thanks! On May 14, 5:02 pm, Romain Guy <[email protected]> wrote: > It used to be called something like that but we decided to unify the > names across all widgets. > > On Thu, May 14, 2009 at 7:58 AM, Streets Of Boston > > > > <[email protected]> wrote: > > > As a side-note: I think the TextView's (and EditText) 'gravity' should > > have been called 'alignment'. It's called that way in most UI's. :=) > > > On May 14, 10:54 am, Romain Guy <[email protected]> wrote: > >> 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 <[email protected]> > >> 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 > >> [email protected] > > >> 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- Hide quoted > >> text - > > >> - Show quoted text - > > -- > Romain Guy > Android framework engineer > [email protected] > > 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

