It depends :) A LinearLayout has a major and a minor axis. The major axis is the one that corresponds to the orientation of the LinearLayout. The android:gravity attribute of a LinearLayout applies only to the major axis and applies to all of the children as one group. For instance, you can use android:gravity="center_horizontal" to center horizontally all of the children of a horizontal LinearLayout. The android:layout_gravity applies to the minor axis and affects one child at a time. For instance, android:layout_gravity="bottom" would work in a horizontal LinearLayout but NOT in a vertical LinearLayout.
In a RelativeLayout you can use android:gravity to affect the position of all of the children at once, either horizontally or vertically. If you want to move only one child at a time, use the various android:layout_* attribute offered by RelativeLayout.LayoutParams. If nothing is working for you, open HierarchyViewer and look at the bounds of each container. Do you even have enough space to actually do any centering? For instance, if your layouts are all using wrap_content for their height and you try to center things vertically, chances are it won't work, since there won't be space left in which to center the children. On Wed, Feb 3, 2010 at 5:51 PM, Jason Proctor <[email protected]> wrote: > i have a LinearLayout with some dynamically shown/hidden items, and i'm > trying to centre it horizontally in a RelativeLayout or LinearLayout. > > seems like there are more than a few ways of specifying alignment and > centring etc. i've tried layout_centerHorizontal and layout_gravity, > nothing's working. > > which is the correct incantation for this case? > > thanks much > -- > jason.vp.engineering.particle > > -- > 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 > -- 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

