Reputation: 3011
I am new to android development and your help would be appreciated,
I want to display 2 rows of 6 buttons like shown in image below, I tried the following code, but when I run it, it doesn't show the app( blank screen appears), the first linearlayout is horizontal and second one is vertical
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<Button
android:id="@+id/Button01"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/tenP" />
<Button
android:id="@+id/Button02"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/TwentyP" />
<Button
android:id="@+id/Button03"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/ThirtyP" />
<Button
android:id="@+id/Button04"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/FourtyP" />
<Button
android:id="@+id/Button05"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/FiftyP" />
<Button
android:id="@+id/Button06"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/SixtyP" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<Button
android:id="@+id/button1"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/PlusOne" />
<Button
android:id="@+id/button2"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/MinusOne" />
<Button
android:id="@+id/button3"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/PlusFive" />
<Button
android:id="@+id/button4"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/MinusFive" />
<Button
android:id="@+id/button5"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/PlusTen" />
<Button
android:id="@+id/button6"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/MinusTen" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Upvotes: 1
Views: 71
Reputation: 2252
try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<Button
android:id="@+id/Button01"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/tenP" />
<Button
android:id="@+id/Button02"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/TwentyP" />
<Button
android:id="@+id/Button03"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/ThirtyP" />
<Button
android:id="@+id/Button04"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/FourtyP" />
<Button
android:id="@+id/Button05"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/FiftyP" />
<Button
android:id="@+id/Button06"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/SixtyP" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
<Button
android:id="@+id/button1"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/PlusOne" />
<Button
android:id="@+id/button2"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/MinusOne" />
<Button
android:id="@+id/button3"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/PlusFive" />
<Button
android:id="@+id/button4"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/MinusFive" />
<Button
android:id="@+id/button5"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/PlusTen" />
<Button
android:id="@+id/button6"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:padding="4dp"
android:text="@string/MinusTen" />
</LinearLayout>
</LinearLayout>
you missed this part from your xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
Upvotes: 1