1

I want to use a text view in my Android layout, the text should be rotated by 90 degrees to the left. The width of the text view is rather small (20dp). My code looks like this:

        <TextView
            android:id="@+id/txtVw"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:minWidth="20dp"
            android:maxWidth="20dp"
            android:paddingEnd="6dp"
            android:rotation="270"
            android:text="Test"/>

The rotation is done, but only those characters are shown that would be visible without the rotation - but there is enough space to show all of them. Does anyone have an idea?

1 Answers1

0

I think it is really a bug, but I found a solution without a custom TextView by my own - I post it if someone else needs a solution for this:

    <TextView
        android:id="@+id/txtVwOne"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:height="20dp"
        android:gravity="end"
        android:maxWidth="40dp"
        android:minWidth="40dp"
        android:rotation="270"
        android:text="Test" />

    <TextView
        android:id="@+id/txtVwTwo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="fill"
        android:layout_weight="1"
        android:layout_marginLeft="-20dp"
        android:minHeight="40dp" />

The trick is to set the min and max width to a value that will allow the text not to be cut in horizontal alignment. The layout height must be set to the height you want it to be. The height attribut must be set to target width of the text view. The following text view must contain android:layout_marginLeft="-20dp" to make sure that it is moved by 20 dp to the left (the target position).