Demo_picture

I want to make Fold in the right aligned to baseline of Hello.

I was wondering can I do this in LinearLayout ?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layoutDirection="locale"
        android:textDirection="locale"
        android:orientation="horizontal">

    <LinearLayout
            android:id="@+id/text_views"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:orientation="vertical">

        <TextView
                android:id="@+id/header"
                android:text="Hello"
                android:textSize="17sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:includeFontPadding="false"
        />

        <TextView
                android:id="@+id/description_text"
                android:text="Just say hello to everybody"
                android:textSize="12sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:includeFontPadding="false"
        />
    </LinearLayout>

    <Space
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="1"
    />

    <TextView
            android:id="@+id/dismiss_btn"
            android:text="Fold"
            android:textSize="13sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:includeFontPadding="false"
            android:layout_alignBaseline="@+id/header"
            android:layout_gravity="center|end"
    />
</LinearLayout>

1 Answers

0
User123456789 On

I don't know if it's appropriate to use weight to emulate android:layout_alignBaseline, but it seems working.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layoutDirection="locale"
        android:textDirection="locale"
        android:orientation="horizontal">

    <LinearLayout
            android:id="@+id/text_views"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:orientation="vertical">

        <TextView
                android:id="@+id/header"
                android:text="Hello"
                android:textSize="17sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:includeFontPadding="false"
        />

        <TextView
                android:id="@+id/description_text"
                android:text="Just say hello to everybody"
                android:textSize="12sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:includeFontPadding="false"
        />
    </LinearLayout>

    <Space
            android:layout_width="0dp"
            android:layout_height="1dp"
            android:layout_weight="1"
    />

    <LinearLayout
            android:id="@+id/text_label"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:orientation="vertical">
    <TextView
            android:id="@+id/dismiss_btn"
            android:text="Fold2"
            android:textSize="13sp"
            android:layout_width="wrap_content"
            android:layout_weight="0.57"
            android:layout_height="0dp"
            android:includeFontPadding="false"
            android:layout_gravity="center|end"
            android:gravity="bottom"
    />
        <Space
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:layout_weight="0.43"
        />
    </LinearLayout>
</LinearLayout>

With the text sizes from the left : 17sp & 12sp, the weight of the upper textview should be 17 / (17+12) = 0.59. But I found 0.57 has better align.

enter image description here