Agustin Lo Castro Agustin Lo Castro - 17 days ago 8
Android Question

Center text for a title and subtitle

I need to place a title and subtitle in this way:

|----------App Name and Version----------|
|--------------------My Company----------|


I'm confused, I just can't solve it.

Answer

Yes, this is easily achievable by using RelativeLayout.

You can specify alignEnd attribute on the second TextView and pass the id of the first TextView. Also, you will have to specify layoutBelow attribute and pass in again the id of the first TextView.

Also, if the first TextView is centered horizontally, you can set centerHorizontal attribute to true.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/text_view_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
    />

    <TextView
        android:id="@+id/text_view_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/text_view_1"
        android:layout_below="@+id/text_view_1"
    />
</RelativeLayout>