dimanche 17 mai 2015

Android rotate TextView by 90 degrees

I'm trying to achieve the following layout.

enter image description here

Its basically a TextView that is rotated by 90 degrees and, after the rotation, has an width of 50dp and an height of all the screen.

I've created a relative layout with an android:layout_width="50dp" and android:layout_height="match_parent" and placed the TextView I want to rotate inside this layout.

This is the layout.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/main"
    >

    <TextView
        android:layout_width="300"
        android:layout_height="match_parent"
        android:id="@+id/first"
        />

    <RelativeLayout
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true">

        <TextView
            android:id="@+id/label"
            android:text="Start text uyriyrytiytitiutyiytityiytyiyiyutyuttyututtyiytitityit utotyutityiitytiytytitiytyti End text"
            android:rotation="90"
            android:visibility="visible"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true" />
    </RelativeLayout>
</RelativeLayout>

I've tried many of the options using android:rotation, android:rotationX, android:rotationY, android:transformPivotX and android:transformPivotY and never managed to achieve what I want.

With UI Automator Viewer I'm getting this for the TextView:

enter image description here

With bounds [35,409][480,484]

And the RelativeLayout where the TextView is placed is showing like this:

enter image description here

With bounds [405,38][480,854]

Can someone explain me what I'm doing wrong? I'm going crazy with this...

Aucun commentaire:

Enregistrer un commentaire