Thanks Mark, I think you managed to clarify for me why it's not
working.
And yes, I'm now convinced that RelativeLayout is the correct option
in this case.

I believe that layout_gravity (for LinearLayout) probably only has an
effect if it specifies a direction that is orthogonal to the
orientation of the layout.
Ie if the LinearLayout orientation is horizontal then the only
acceptable layout_gravity options fors its children are top, bottom
etc (and NOT left, right, center_horizontal).

Happy now. Thanks everyone.

On Sep 1, 8:18 am, Mark Carter <mjc1...@googlemail.com> wrote:
> LinearLayout is for when you want a continuous sequence of children in
> a line, one after another. From your description, that is not what you
> want (e.g. there may be a gap between the buttons depending on their
> sizes and the size of the parent).
>
> So a LinearLayout is not what you should be using.
>
> Your requirements show that the buttons need to be placed relative to
> the parent, so (like others have said) a RelativeLayout is the best
> option, using attributes like layout_alignParentRight and
> layout_centerHorizontal.
>
> On Aug 31, 5:42 am, William Ferguson <william.ferguson...@gmail.com>
> wrote:
>
> > OK, I'm obviously missing something fundamentally simple here.
> > I have a LinearLayout containing 2 buttons.
> > I've coloured the layout background red so I can see that it has
> > expanded to fill its parent.
> > I wanted the BooButton to center horizontally within the layout and
> > the OtherButton to be right justified.
> > But both buttons are on the left of the layout.
>
> > What have I done wrong?
>
> > <LinearLayout android:id="@+id/buttonBlock"
> >    android:orientation="horizontal"
> >    android:background="#ff0000"
> >    android:layout_width="fill_parent"
> >    android:layout_height="wrap_content">
>
> >   <Button android:id="@+id/booButton"
> >        android:text="Boo"
> >        android:layout_gravity="center_horizontal"
> >        android:layout_width="wrap_content"
> >        android:layout_height="wrap_content"/>
>
> >   <Button android:id="@+id/otherButton"
> >        android:text="Other"
> >        android:layout_gravity="right"
> >        android:layout_width="wrap_content"
> >        android:layout_height="wrap_content"/>
> >  </LinearLayout>

-- 
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