vertical alignment of the text views of different linear layouts

Viewed 421

I am trying to create a screen that shows the details of the students. The following is my xml code for that screen.

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".PatientDetails">

    <LinearLayout
        android:id="@+id/ll1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="3"
        android:background="@color/BackgroundColor">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Details"
                android:textColor="@color/white"
                android:textSize="30dp"
                android:gravity="center"/>
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:background="@color/white">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="16dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:layout_marginTop="16dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Student Name"
                        android:textSize="20dp"
                        android:layout_weight="1"
                        android:textColor="@color/BackgroundColor"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/PatientName"
                        android:text="Joseph"
                        android:layout_weight="1"
                        android:textSize="20dp"
                        android:textColor="@color/BackgroundColor"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:layout_marginTop="16dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Age"
                        android:textSize="20dp"
                        android:layout_weight="1"
                        android:textColor="@color/BackgroundColor"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/age"
                        android:text="21"
                        android:layout_weight="1"
                        android:textSize="20dp"
                        android:textColor="@color/BackgroundColor"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:layout_marginTop="16dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Sex"
                        android:textSize="20dp"
                        android:layout_weight="1"
                        android:textColor="@color/BackgroundColor"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/Sex"
                        android:text="Female"
                        android:layout_weight="1"
                        android:textSize="20dp"
                        android:textColor="@color/BackgroundColor"/>
                </LinearLayout>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
</LinearLayout>

The output of the code is as follows: enter image description here Can someone tell me how to modify the code so that the values on the right hand side of each row are aligned properly.

3 Answers
Related