Android: Placing the Buttons below the Text and not in the same line
12,214
Try this. You can, in fact, just copy and paste it. Change the attributes and you are good to go.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/txtScoreLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Score" />
<TextView
android:id="@+id/txtScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txtScoreLabel"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/txtScoreLabel"
android:text="0" />
<Button
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtScoreLabel"
android:layout_below="@+id/txtScoreLabel"
android:text="Button One" />
<Button
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/one"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/one"
android:text="Button Two" />
</RelativeLayout>
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
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.