Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning baseline of two text views in Android

please find below my layout & its result ; I need the text 'Text message' to align on the baseline of the text 'Header'(Please find below the code and snapshot). Would be glad if someone can give me direction

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0"
android:baselineAligned="true"
>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:background="@color/custom_orange"
    android:gravity="center"
    >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Header"
        android:textSize="25sp"
        android:id="@+id/title"
        android:gravity="center"
        android:background="@color/custom_red"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Text message"
        android:textSize="10sp"
        android:id="@+id/language"
        android:gravity="center"
        android:background="@color/custom_green"/> 
</LinearLayout>

</LinearLayout>

This is the result

enter image description here

This is what I need

enter image description here

like image 850
Raj Avatar asked Nov 08 '14 22:11

Raj


Video Answer


1 Answers

Use RelativeLayout as a container for TextViews and add the attribute

android:layout_alignBaseline="@+id/title"

to id/language TextView

like image 185
x11 Avatar answered Oct 07 '22 16:10

x11