Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Align different font-sizes on same baseline

I have 2 adjacent TextViews, each with a different string that has a different font size. I want the text to have the same baseline in each TextView. How can I do this?

Here is my layout:

   <LinearLayout
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:background="@color/colorAccentLight"
            android:textSize="18sp"
            style="@style/Base.TextAppearance.AppCompat.Medium"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="bottom"
            android:textAlignment="gravity"
            android:text="30"
        />
        <TextView
            android:background="@color/colorAccent"
            android:text="hello"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="bottom"
            android:textAlignment="gravity"
        />

    </LinearLayout>

Here is the current behavior, notice how the 2 TextViews have different baselines (the "hello" is lower than the 30) because the font for each TextView is a different size.

enter image description here

like image 793
Roymunson Avatar asked Dec 24 '22 01:12

Roymunson


1 Answers

In ConstraintLayout you can simply use

app:layout_constraintBaseline_toBaselineOf="@+id/textView1"
like image 174
Francis Avatar answered Dec 26 '22 00:12

Francis