android - How to display code snippet in textview? -
i'm trying display code snippet in textview.but cannot make long text line auto scrollable horizontally in textview.
code:
textview code = new textview(getactivity()); tablerow.layoutparams paramsexample = new tablerow.layoutparams(tablerow.layoutparams.match_parent,tablerow.layoutparams.wrap_content); code.setbackgroundcolor(getresources().getcolor(android.r.color.black)); code.setpadding(5, 5, 5, 5); code.settextcolor(getresources().getcolor(android.r.color.white)); code.settextsize(typedvalue.complex_unit_sp,12); code.setclickable(true); code.setlayoutparams(paramsexample); setcode(code, r.raw.codesnippet); ll.addview(code);
i'm creating textview in fragment.fragment_layout.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fragment_ll" android:orientation="vertical"> </linearlayout>
and starting fragment in activity in coordinatorlayout > nestedscrollview > linearlayout(fragment container)
each one's width size "match parent"
this setcode method:
public void setcode(textview tv, int rawid) { resources res = getresources(); bufferedreader input = new bufferedreader(new inputstreamreader( res.openrawresource(rawid))); stringbuffer sb = new stringbuffer(); try { string line; while ((line = input.readline()) != null) { sb.append(line); } } catch (ioexception e) { e.printstacktrace(); } { try { input.close(); } catch (ioexception e) { e.printstacktrace(); } } spanned spannedcode = html.fromhtml(sb.tostring()); tv.settext(spannedcode); }
i got code snippet (codesnippet.txt) vim:tohtml.
but not scroll horizontally.what should make auto scrollable horizontally webview ?
after horizontalscrollview , code.sethorizontallyscrolling(true):
horizontal scrolling works fine in single line.i need display code snippet block.
your textview
should inside horizontalscrollview
following:
<horizontalscrollview android:layout_width="fill_parent" android:layout_height="fill_parent"> <textview android:layout_width="40dp" android:layout_height="wrap_content" android:scrollhorizontally="true" android:text="horizontal scroll view"/> </horizontalscrollview>
Comments
Post a Comment