Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can you display upside down text with a textview in Android?
    text
    copied!<p>How can you display upside down text with a textview in Android?</p> <p>In my case I have a 2 player game, where they play across from each other. I want to display test to the second player oriented to them.</p> <hr> <p>This was the solution I implemented after AaronMs advice</p> <p>The class that does the overriding, bab.foo.UpsideDownText </p> <pre><code>package bab.foo; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.widget.TextView; public class UpsideDownText extends TextView { //The below two constructors appear to be required public UpsideDownText(Context context) { super(context); } public UpsideDownText(Context context, AttributeSet attrs) { super(context, attrs); } @Override public void onDraw(Canvas canvas) { //This saves off the matrix that the canvas applies to draws, so it can be restored later. canvas.save(); //now we change the matrix //We need to rotate around the center of our text //Otherwise it rotates around the origin, and that's bad. float py = this.getHeight()/2.0f; float px = this.getWidth()/2.0f; canvas.rotate(180, px, py); //draw the text with the matrix applied. super.onDraw(canvas); //restore the old matrix. canvas.restore(); } } </code></pre> <p>And this is my XML layout:</p> <pre><code>&lt;bab.foo.UpsideDownText android:text="Score: 0" android:id="@+id/tvScore" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" &gt; &lt;/bab.foo.UpsideDownText&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload