Mirror text in text mode?

I'm trying to make an application that just displays a bunch of text on the android screen, the problem is that it should be mirrored (it will be considered as "hud").

Surprisingly, in Android 4.0 you can do this with a text view simply by going textview.setScaleX (-1) ... to 4.0. I can not find much. textview.setTextScaleX (-1) does not work (in fact, it does not work correctly, but only one char appears, although it is a mirror). Approach 4.0 also works on my phone (nexus s running cm9).

I came across several suggestions, such as using AndroidCharacter.Mirror () without success, and it seems that I have 3 options left:

1) Write a custom (mirror) font 2) find out how to override onDraw (according to Android TextView mirroring (hud)? ) 3) draw it all on the canvas.

The first is believable, and I could do it, but it limits me to one language (or a lot of work). Second + third Im pretty lost, although I'm sure I can figure it out from a few examples that I found (for example: Drawing mirror text on canvas ).

Before attempting 2 or 3, are there any other options that I may not have considered?

+4
source share
1 answer

Im pretty sure this is not possible using pre-4.0 TextView.

Custom mirrored TextView is not that complicated:

package your.pkg; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.widget.TextView; public class MirroredTextView extends TextView { public MirroredTextView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { canvas.translate(getWidth(), 0); canvas.scale(-1, 1); super.onDraw(canvas); } } 

And use like:

 <your.pkg.MirroredTextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World" /> 
+7
source

Source: https://habr.com/ru/post/1384644/


All Articles