I have a TextView and 3 Buttons centered in a RelativeLayout, and the text in all three of them is left-justified with the parent center as the leftmost line.
I’ve tried changing the gravity of the TextView, Buttons, and layout but nothing is working and I’m baffled because I’ve never seen Android align text like this before.
I want the Button text to be centered within each Button and the top text to be center-justified.
An image of what it looks like is here: https://i.stack.imgur.com/9lHEd.png
Here’s my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:gravity="center_horizontal"
android:text="@string/greeting"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/startQuizButton"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:onClick="@string/startQuiz"
android:text="@string/start_quiz" />
<Button
android:id="@+id/lessonsButton"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_below="@+id/startQuizButton"
android:layout_centerHorizontal="true"
android:onClick="@string/startLesson"
android:text="@string/lessonsString" />
<Button
android:id="@+id/viewAllButton"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_below="@+id/lessonsButton"
android:layout_centerHorizontal="true"
android:onClick="@string/showAll"
android:text="@string/view_all" />
I included a
RelativeLayoutbecause you have it as your parent layout. However, i am not sure that it is needed. See if the following code is what you are looking for.