Search code examples
androidxmlkotlintextviewvertical-text

Why the vertical TextView taking different spaces -android-


I have a TextView inside CardView. after rotation (-90 or 270), each textView had different space from ImageView

The result is like this: (https://i.sstatic.net/ad9r1.jpg)

XML:

<TextView
    android:id="@+id/number"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="123456789"
    android:rotation="-90"
    app:layout_constraintStart_toEndOf="@id/image_item"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"/>

I tried to put the TextView inside LinearLayout but the output is the same. if there any solution (using just XML) please tell me.

i found this on stackoverflow : Vertical TextView taking too much space in Android but the result is the same and i am looking for solution using XML code


Solution

  • I just changed layout_height to 0dp and modified the layout_constraint, like the code below:

    <TextView
    android:id="@+id/number"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:text="123456789"
    android:rotation="-90"
    app:layout_constraintStart_toEndOf="@id/image_item"
    app:layout_constraintTop_toTopOf="@id/image_item"
    app:layout_constraintBottom_toBottomOf="@id/image_item"/>
    

    Now, no matter the length of the text, it will be attached to view next to it.