tags:

views:

3099

answers:

2

Hi,

I try to create 2 rows of buttons in android layout.xml file. The first row is left-aligned, the second row is center-aligned.

Here is what I did, but I end up getting 1 row of buttons. Can you please tell me what am I doing wrong?

enter code here
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content"
android:layout_height="fill_parent">
 <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:layout_gravity="bottom|left"
        >
         <Button 
          android:id="@+id/btn1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          />
        </LinearLayout>
     <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:layout_gravity="bottom|center"
        >
         <Button 
          android:id="@+id/btn2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          />
       <Button 
          android:id="@+id/btn3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          />
        </LinearLayout>
</FrameLayout>
</pre>
+3  A: 

FrameLayout is wrong for this task. Use LinearLayout like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="fill_parent">
 <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:layout_gravity="bottom|left"
        >
         <Button
          android:id="@+id/btn1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          />
        </LinearLayout>
     <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal"
          android:layout_gravity="bottom|center"
        >
         <Button
          android:id="@+id/btn2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          />
       <Button
          android:id="@+id/btn3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          />
        </LinearLayout>
</LinearLayout>

for explanation on what FrameLayout is for go here: http://developer.android.com/reference/android/widget/FrameLayout.html

Reflog
A: 

You could also use just one RelativeLayout instead of all of your layouts. I've read many reports that RelativeLayout uses less resources than LinearLayout.

Erik B