Android: Placing the Buttons below the Text and not in the same line


Ask by : user221287 November 06, 2012 16:02

I am making a simple Android Application.

This is the XML code:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Score: "
    tools:context=".Adder" />
<TextView
    android:id="@+id/score"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0"
    tools:context=".Adder" />
<Button
    android:id="@+id/one"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:text="1"
    android:textSize="20dp" />

<Button
android:id="@+id/two"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="2"
android:textSize="20dp" />

which is giving the output: http://flic.kr/p/dqwmT9

But, I want the Buttons to be present below the "Score: 0"

I have tried a few things, which are giving the output: http://flic.kr/p/dqwbxD

What can I do to fix this?

NOTE: I have given the link because I do not have enough reputation to upload photos.

View original question

Answer by : user221287November 06, 2012 16:02

Just use the Relative Layout instead of Linear Layout.

<Button
android:id="@+id/one"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_below="@id/score_text"
android:text="1"
android:textSize="20dp" />

View original answer