0

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>

enter image description here enter image description here

xadun
  • 146
  • 2
  • 11
  • Could you post your current xml for this layout? – Much Overflow Dec 27 '15 at 14:29
  • I've tried to rotate programmatically (using `TextView.setRotation(90)` and even using `animation` but it doesn't work as well.. I searched everywhere and I can't find a solution, I'm almost using it in the horizontal (default) orientation but, as the `marginLeft` is related to the left side of the TextView boundary (the "blue box" in the image around the text) I can't keep the text centered in the line.. I can't believe that there isn't a way to fix it.. – xadun Dec 28 '15 at 00:22
  • I see. You are better of writing a custom TextView that updates its bounds as well. Refer this for an example http://stackoverflow.com/questions/2888780/is-it-possible-to-write-vertically-in-a-textview-in-android/17001995#17001995 – Much Overflow Dec 28 '15 at 05:50
  • Thank you @MuchOverflow, I'll have a look on that! – xadun Dec 28 '15 at 13:40
  • 1
    @MuchOverflow it worked! Finally! Please answer the question and I'll accept it as correct. – xadun Dec 28 '15 at 20:04

1 Answers1

1

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.

Community
  • 1
  • 1
Much Overflow
  • 3,142
  • 1
  • 23
  • 40