无法在android中使用mathview显示数学方程式

时间:2017-07-09 02:23:01

标签: android

我正在开发一个Android应用程序,我需要在我的应用程序中显示数学方程式。我决定在stackoverflow上使用kexanie mathview库,但我无法理解如何使用它。 在github上有一个例子,当我复制粘贴下面给出的代码时。它显示“Webview”而不是数学方程式。

<io.github.kexanie.library.MathView
    android:id="@+id/formula_one"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    auto:text="When \\(a \\ne 0\\), there are two solutions to \\(ax^2 + bx + c = 0\\)
    and they are $$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$"
    auto:engine="MathJax"
    >
</io.github.kexanie.library.MathView>

2 个答案:

答案 0 :(得分:0)

您需要将依赖项添加到build.gradle文件:

dependencies {
    compile 'io.github.kexanie.library:MathView:0.0.6'
}

了解更多here

答案 1 :(得分:0)

What namespace you are importing for "Auto".  
   it should be "http://schemas.android.com/apk/res-auto"  I tested it and 
   it is working fine.

Tyr给出了第二个例子:

  public class MainActivity extends AppCompatActivity {
MathView formula_two;
String tex = "This come from string. You can insert inline formula:" +
        " \\(ax^2 + bx + c = 0\\) " +
        "or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
    super.onResume();

    formula_two = (MathView) findViewById(R.id.formula_two);
    formula_two.setText(tex);
}
  } 

XML:

 <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
    <io.github.kexanie.library.MathView
    android:id="@+id/formula_two"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    auto:engine="KaTeX"
    >
</io.github.kexanie.library.MathView>l