textview中的镜像文本? [英] Mirrored text in textview?

查看:23
本文介绍了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(-1)... 在 4.0 之前使用 textview 来执行此操作,但我找不到太多.textview.setTextScaleX(-1) 不起作用(实际上它有点起作用,但只有一个字符出现,尽管它是镜像的).4.0 的方法也适用于我的手机(nexus 运行 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() 没有成功,我似乎只剩下 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.

第一个是合理的,我可能可以做到,但它限制了我使用一种语言(或大量工作).第二个和第三个我很迷茫,尽管我很确定我可以从我找到的几个例子中弄清楚(例如:在画布上绘制镜像文本).

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?

推荐答案

我很确定使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆