MathView - 展示数学公式的Android视图

jopen 8年前

介绍:

一个第三方视图用于轻松在Android应用展示数学公式的view。有两种渲染引擎:MathJax and KaTeX. 支持Android 版本4.1 (Jelly Bean) and newer。它其实是用Webview+js实现的。

运行效果:

使用说明:

依赖

dependencies {      compile fileTree(include: ['*.jar'], dir: 'libs')      compile 'com.android.support:appcompat-v7:23.0.0'      compile 'io.github.kexanie.library:MathView:0.0.4'  }

在布局文件中定义MathView

例如:

<LinearLayout ...>        <TextView          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:text="Formula one: from xml with MathJax"          android:textStyle="bold"/>        <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>        <TextView          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:text="Formula two: from Java String with KaTeX"          android:textStyle="bold"/>        <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>    </LinearLayout>

在Activity中获得实例

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);      }  }

 

官方网站:http://www.open-open.com/lib/view/home/1451983671448