Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Rotate TextView 90 Degrees and display [duplicate]

Tags:

android

I am having a situation in Graph page where LinearLayout should display the TextView with 90 degrees rotated.

like image 687
sakshi Avatar asked Jan 22 '12 04:01

sakshi


2 Answers

Try this::

<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:rotation="-95"
                android:text="2" 
                />
like image 122
vijay Avatar answered Nov 15 '22 20:11

vijay


The fastest and most convenient way is to Rotate by Animation

use rotate animation on your regular TextView like so.

rotateAnimation.xml:

<rotate  xmlns:android="http://schemas.android.com/apk/res/android"
           android:fromDegrees="0" 
           android:toDegrees="-90"
           android:pivotX="50%"
           android:duration="0"
           android:fillAfter="true" />

Java Code:

  TextView text = (TextView)findViewById(R.id.txtview);       
  text.setText("rotated text here");

  RotateAnimation rotate= (RotateAnimation)AnimationUtils.loadAnimation(this,R.anim.rotateAnimation);
  text.setAnimation(rotate);
like image 42
Rotemmiz Avatar answered Nov 15 '22 19:11

Rotemmiz