How to Rotate TextView 90 Degrees and display
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);
Rotate total Textview in -90 degrees
for a vertical TextView i used the following code and it worked perfectly.
public class VerticleTextView extends TextView {
final boolean topDown;
public VerticleTextView(Context context, AttributeSet attrs){
super(context, attrs);
final int gravity = getGravity();
if(Gravity.isVertical(gravity) && (gravity&Gravity.VERTICAL_GRAVITY_MASK) == Gravity.BOTTOM) {
setGravity((gravity&Gravity.HORIZONTAL_GRAVITY_MASK) | Gravity.TOP);
topDown = false;
}else
topDown = true;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
@Override
protected void onDraw(Canvas canvas){
TextPaint textPaint = getPaint();
textPaint.setColor(getCurrentTextColor());
textPaint.drawableState = getDrawableState();
canvas.save();
if(topDown){
canvas.translate(getWidth(), 0);
canvas.rotate(90);
}else {
canvas.translate(0, getHeight());
canvas.rotate(-90);
}
canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
getLayout().draw(canvas);
canvas.restore();
}
}
how to rotate a textView in android?
you can use rotate function in xml
android:rotation="-180"
for dynamic use
textview.setRotation(-180);
How to Rotate TextView?
Change the 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>
Related Topics
How to Change the Proguard Mapping File Name in Gradle for Android Project
How to Use Getlistview() in Activity
Savedinstancestate Is Always Null in Fragment
Clear All Activities in a Task
Strange Behavior of Android Videoview - "Can't Play Video"
My Android Camera Uri Is Returning a Null Value, But the Samsung Fix Is in Place, Help
How to Detect "Recent Apps" System Button Clicks (Honeycomb+)
Displaying Android Asset Files in a Webview
Detecting Gps On/Off Switch in Android Phones
Updated Sdk Version, Getting Classnotfoundexception: Android.Support.V4.View.Viewpager
Android Webview VS Phone Browser
How to Launch the 'Add Contact' Activity in Android
How to Use the Speechrecognizer API Directly for Speech Input
Can Gradientcolor Be Used to Define a Gradient for a Fill or Stroke Entirely in Xml
Android Sax Parser Not Getting Full Text from Between Tags