How to rotate a textview with 180 degrees rotated in Android?
As some games that the half of screen rotated 180 degrees for 2nd player
as you can see in this picture
How to rotate a textview with 180 degrees rotated in Android?
As some games that the half of screen rotated 180 degrees for 2nd player
as you can see in this picture
you can use rotate function in xml
android:rotation="-180"
for dynamic use
textview.setRotation(-180);
I have made this custom textview i have same requirement like you hope this will help you..just change degree values as per your need..
public class VerticalTextView extends TextView {
final boolean topDown;
public VerticalTextView( 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();
}
}
If you still need help please inform me
To rotate TextView, use:
android:rotation="180"
Place this within the required Textview tags.