2012-02-05 46 views

回答

2

你究竟意味着什麼?您可能需要將TextViewTypeface更改爲monospace,這將使您的TextView在此處的代碼塊看起來類似於stackoverflow。

This font is monospace

代碼,使它看起來像這樣:

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:typeface="monospace" 
     android:text="This font is monospace" /> 

或Java中:

yourTextview.setTypeface(Typeface.MONOSPACE, Typeface.NORMAL); 

編輯:

所以,你需要一些Java代碼格式化庫,最好的情況是如果它返回HTML代碼的結果,所以它可以很容易地p進入TextView

我不知道是否有這樣的自由,但在這裏,你可能感興趣的一些資源:

How to pretty print XML from Java?

Stand-alone Java code formatter/beautifier/pretty printer?

EDIT2:

你也可以使用以下JavaScript庫之一:

  1. http://alexgorbatchev.com/SyntaxHighlighter/

  2. http://code.google.com/p/google-code-prettify/

定製WebView顯示相當格式化代碼一起。

+0

不完全,我的意思是這個http://ditaa-addons.sourceforge.net/helloworld-src.gif – stormx1 2012-02-05 15:32:35

+0

我編輯了我的答案。我希望它有幫助。 – 2012-02-05 15:42:38