7 messages in com.googlegroups.android-developers[android-developers] Re: Problem Cent...
FromSent OnAttachments
Kyle R29 Apr 2008 17:32 
Mark Murphy29 Apr 2008 18:04 
Kyle R29 Apr 2008 18:51 
Kyle R29 Apr 2008 19:13 
Romain Guy29 Apr 2008 19:20 
Romain Guy29 Apr 2008 19:21 
Kyle R29 Apr 2008 19:36 
Subject:[android-developers] Re: Problem Centering and Padding Buttons in Layout
From:Kyle R (kyle@gmail.com)
Date:04/29/2008 06:51:20 PM
List:com.googlegroups.android-developers

That worked perfectly, thank you very much.

On Apr 29, 9:05 pm, Mark Murphy <mmur@commonsware.com> wrote:

Kyle R wrote:

I cannot figure out how to make 4 buttons, arranged vertically in a row, centered both vertically and horizontally on the screen.  I don't get why this is so difficult.  Is there a complete list of button attributes for the xml file and what they accomplish somewhere?

What I am trying to achieve would look like:

<- - - - ->

     1      2      3      4

<- - - - ->

Try this:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"         android:orientation="vertical"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:gravity="center"         >         <LinearLayout                 android:orientation="vertical"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:gravity="center"                 >                 <Button                           android:id="@+id/btn1"                           android:layout_width="300px"                           android:layout_height="50px"                           android:textAlign="center"                           android:padding="15px"                           android:text="1"/>                 <Button                           android:id="@+id/btn2"                           android:layout_width="300px"                           android:layout_height="50px"                           android:textAlign="center"                           android:padding="15px"                           android:text="2"/>                 <Button                           android:id="@+id/btn3"                           android:layout_width="300px"                           android:layout_height="50px"                           android:textAlign="center"                           android:padding="15px"                           android:text="3"/>                 <Button                           android:id="@+id/btn4"                           android:layout_width="300px"                           android:layout_height="50px"                           android:textAlign="center"                           android:padding="15px"                           android:text="4"/>         </LinearLayout> </LinearLayout>

I'll admit I'm not 100% certain why both gravity:"center" attributes are needed -- I'd've expected the one on the outer-most LinearLayout would have done the trick. But, this seems to give the visual effect you're looking for, if I understood you correctly.

- Show quoted text -