I'm trying to do something like the image below, where I have a rotated (90°) TextView
with marginLeft
related to the ImageView
. The problem is, when I increase the TextView
value, say 2 to 2000000, it move to the right, behaving like a non-rotated TextView
(see the blue square around it). How can I fix it?
Thank you!
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/iv_flange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp"
android:adjustViewBounds="true"
android:contentDescription="@string/title"
android:scaleType="matrix"
android:src="@drawable/drawing_flange" >
</ImageView>
<TextView
android:id="@+id/tv_dimC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_flange"
android:layout_alignTop="@+id/iv_flange"
android:layout_marginLeft="90dp"
android:layout_marginTop="210dp"
android:gravity="left"
android:rotation="270"
android:text="Ø1200"
android:textColor="#000"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_dimd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_flange"
android:layout_alignTop="@+id/iv_flange"
android:layout_marginLeft="-25dp"
android:layout_marginTop="215dp"
android:gravity="center"
android:textAlignment="center"
android:rotation="270"
android:text="Ø200000000000"
android:textColor="#000"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_dime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_flange"
android:layout_alignTop="@+id/iv_flange"
android:layout_marginLeft="40dp"
android:layout_marginTop="145dp"
android:gravity="center"
android:rotation="270"
android:text="300"
android:textColor="#000"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_dimf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_flange"
android:layout_alignTop="@+id/iv_flange"
android:layout_marginLeft="140dp"
android:layout_marginTop="-15dp"
android:gravity="center"
android:rotation="0"
android:text="75"
android:textColor="#000"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_dimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/iv_flange"
android:layout_alignTop="@+id/iv_flange"
android:layout_marginLeft="190dp"
android:layout_marginTop="-15dp"
android:gravity="center"
android:rotation="0"
android:text="130"
android:textColor="#000"
android:textSize="14sp" />
</RelativeLayout>
Even when you rotate your TextView using android:rotaion
in xml or myTextView.setRotation()
in the Java code, the bounds of the text view will not update to the angle you rotated the text view into. To overcome this you may write a custom TextView
that draws itself in the correct angle you require it to. Please check this answer for a starting point.