1

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

enter image description here

Ekaba Bisong
  • 2,918
  • 2
  • 23
  • 38
hassan moradnezhad
  • 455
  • 2
  • 6
  • 26

3 Answers3

4

you can use rotate function in xml

android:rotation="-180"

for dynamic use

textview.setRotation(-180);
3

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

Lokesh Desai
  • 2,607
  • 16
  • 28
0

To rotate TextView, use:

 android:rotation="180" 

Place this within the required Textview tags.

Abhi
  • 3,431
  • 1
  • 17
  • 35