androidtextviewandroid-layout-weight

Textview text goes down when it's 2 lines


I have below code.

<LinearLayout

    android:layout_marginStart="@dimen/space_10"
    android:layout_marginEnd="@dimen/space_10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="3.2"
    android:orientation="horizontal"
    >

    <TextView
        android:id="@+id/tvDonate"
        android:fontFamily="@font/tajawal_medium"
        android:textSize="@dimen/font_size_14"
        android:textColor="@color/colorPrimary"
        android:background="@drawable/background_yellow_rounded_corner"
        android:gravity="center"
        android:layout_weight="1"
        android:text="@string/text_donation_title"
        android:layout_width="0dp"
        android:layout_height="@dimen/space_48"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        />

    <TextView
        android:id="@+id/tvRecurring"
        android:fontFamily="@font/tajawal_medium"
        android:textSize="@dimen/font_size_14"
        android:textColor="@color/white"
        android:background="@drawable/background_darkergreen_rounded_corner"
        android:gravity="center"
        android:layout_weight="1"
        android:text="@string/recurring_donation"
        android:layout_width="0dp"
        android:layout_height="@dimen/space_48"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        />

    <TextView
        android:id="@+id/tvAddToCart"
        android:fontFamily="@font/tajawal_medium"
        android:textSize="@dimen/font_size_14"
        android:textColor="@color/colorPrimary"
        android:background="@drawable/greenborder_bg_10"
        android:gravity="center"
        android:layout_weight="1"
        android:text="@string/addToCart"
        android:layout_width="0dp"
        android:layout_height="@dimen/space_48"/>

</LinearLayout>

Second textview text get's shifted down.

enter image description here

Any idea why this is happening?


Note : If text is 1 line, all is fine...


Solution

  • Set your textview height to match_parent

    android:layout_height="match_parent"