反映在TextView的文字? [英] Mirrored text in textview?
问题描述
我试着这样做,只是输出一串文字到Android的屏幕,这个问题是一个应用程序,它已被镜像(将被视为一个HUD)。
Im trying to do an application that simply outputs a bunch of text to the android screen, the problem is is that it has to be mirrored (Will be viewed as a "hud").
令人惊讶的是Android 4.0的,你可以通过简单地textview.setScaleX这样与一个TextView(-1)... 4.0之前的我找不到了。 textview.setTextScaleX(-1)不工作(实际上它还挺工作,但只有一个字符出现,虽然它镜像)。 4.0方法也适用于我的手机(Nexus S的运行CM9)。
Surprisingly, in android 4.0, you can do this with a textview by simply going textview.setScaleX(-1)... prior to 4.0 I cant find much. textview.setTextScaleX(-1) doesnt work (actually it kinda works, but only one char comes up, though it is mirrored). The 4.0 approach also works on my phone (nexus s running cm9).
我已经跨越了一些建议迷迷糊糊的,如使用AndroidCharacter.Mirror(),但没有成功,似乎IM留下了3个选项:
I've stumbled across a few suggestions, such as using AndroidCharacter.Mirror() with no success and it seems im left with 3 options:
1)写一个自定义(镜像)字体 2)学会了如何覆盖的OnDraw(按的Android TextView的镜像(HUD)?) 3)油漆这一切到画布上。
1) Write a custom (mirrored) font 2) learn how to override onDraw (as per Android TextView mirroring (hud)?) 3) paint it all onto a canvas.
首先是合理的,我可以大概做了,但我限制在一个单一的语言(或大量的工作)。二+三林相当具有虽然林pretty的肯定,我可以计算出从几个例子我已经找到了(此例如丢失:的>图纸镜文本)。
The first is plausible and i could probably do it, but it limits me to a single language (or a lot of work). The second + third Im quite lost with though Im pretty sure I can figure it out from a few examples i've found (this for example: Drawing mirror text on canvas).
在我尝试2或3,有没有其他的选择,我也许已经不考虑?
Before I do attempt 2 or 3, is there any other options i've perhaps not considered?
推荐答案
林pretty的肯定是不可能的pre-4.0的TextView。
Im pretty sure it is not possible with the pre-4.0 TextView.
镜像定制的TextView并不难:
A mirrored custom TextView is not that hard:
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);
}
}
和为使用:
<your.pkg.MirroredTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World" />
这篇关于反映在TextView的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!