Android - 是否可以在文本上叠加文字?

时间:2012-12-12 11:31:42

标签: android text rendering

我想为Android应用程序创建数学的特殊字符。
我想知道是否可以将一个字符叠加在另一个字符之上,或者如何对文本的呈现方式进行精确控制(以及如何进行此操作)。

4 个答案:

答案 0 :(得分:7)

如果您需要一般方法来显示数学方程式,请查看jqMath。我认为你可以使用WebView来渲染它。

许多数学符号都有Unicode代码点。具体来说,Unicode代码指向' +'的符号。在一个圆圈内是U + 2295。如果字体支持它们,可以直接渲染它们。有关具有相应Unicode代码点的某些数学符号的列表,请选中this Wikipedia article

还可以查看this question在Java中使用MathML的资源。

答案 1 :(得分:1)

我会扩展View类,然后使用你在onDraw方法中收到的Canvas对象的drawText方法。听起来你需要精确控制正在绘制文本的位置的坐标,并且扩展View会给你这样的。看看Canvas.drawText,您可以根据需要使用x和y坐标来叠加文本。

答案 2 :(得分:0)

试试这个:

这样你可以添加Superscript文本:

TextView out_unit2 = (TextView) findViewById(R.id.out_unit2);
out_unit2.setText((Html.fromHtml("meter<sup><small>2</small></sup>")));

下标文字:

TextView out_unit2 = (TextView) findViewById(R.id.out_unit2);
out_unit2.setText((Html.fromHtml("meter<sub><small>2</small></sub>")));

您可以使用此功能为您的代码添加尽可能多的内容。

希望它对你有所帮助。

感谢。

答案 3 :(得分:0)

它可能会很快变得非常混乱,但你可以通过FrameLayout和几个TextViews来完成它。例如,“0”的XML与“+”,上标“+”和下标“ - ”重叠:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="0"
        android:textSize="@dimen/title_bar_font_size" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+"
        android:textSize="@dimen/title_bar_font_size" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+"
        android:textSize="12sp"
        android:layout_marginLeft="12sp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-"
        android:textSize="12sp"
        android:layout_marginLeft="12sp"
        android:layout_gravity="bottom" />
</FrameLayout>

导致:

Output

相关问题