How to rotate a textview?

I want to rotate a TextView, but I cannot get the correct output. I get a textView with some text missing

In the layout

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginTop = "50dip"> <TextView android:layout_width="wrap_content" android:gravity="bottom" android:layout_height="wrap_content" android:id="@+id/text" android:text="Shreeji \n Nath" /> </RelativeLayout> 

In animation

  <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="40" android:toDegrees="-90" android:pivotX="40%" android:duration="0"> </rotate> 

Java file

 import android.app.Activity; import android.os.Bundle; import android.view.animation.AnimationUtils; import android.view.animation.RotateAnimation; import android.widget.TextView; public class VDemo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView)findViewById(R.id.text); RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this,R.anim.myanim); ranim.setFillAfter(true); tv.setAnimation(ranim); } } 
+4
source share
2 answers

Change main.xml to:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:layout_marginTop="50dip" android:layout_marginLeft="50dip" android:id="@+id/text1"></TextView> </RelativeLayout> 
+2
source

Added to API Level 12

 view.animate().rotationBy(90).start() 
+1
source

All Articles