Today, I tried to use the following Android scroll wheel to read the test file from a small test.
It mainly uses the scrollto function and getscrolly ()
The program click the button to scroll down to 2222 and display
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Absolutelayout
Android: Id = "@ + ID/widget38"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Xmlns: Android = "http://schemas.android.com/apk/res/android"
>
<Linearlayout
Android: Id = "@ + ID/widget32"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_x = "0px"
Android: layout_y = "0px"
>
</Linearlayout>
<Scrollview
Android: Id = "@ + ID/SV"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_x = "0px"
Android: layout_y = "20px"
>
<Textview
Android: Id = "@ + ID/txtview"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Hello, user! "
Android: textsize = "20sp"
>
</Textview>
</Scrollview>
<Button
Android: Id = "@ + ID/test"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "button"
Android: layout_x = "230px"
Android: layout_y = "2px"
>
</Button>
</Absolutelayout>
Main. javapackage ZY. scroller; import Java. io. file; import Java. io. fileinputstream; import Java. io. ioexception; import Org. apache. HTTP. util. encodingutils; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. widget. arrayadapter; import android. widget. button; import android. widget. scrollview; import android. widget. textview; import android. widget. toast; public class main extends activity {/** called when the activity is first created. */FINAL Public String dev_file = "/data/ZY. scroller/aaa.txt "; // test file final string text_encoding =" UTF-8 "; scrollview Sv; textview TV; Public button test; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); Sv = (scrollview) findviewbyid (R. id. SV); tv1_(textview1_findviewbyid(r.id.txt view); string STR; STR = getinfo (dev_file); string [] X; X = Str. split ("/R"); TV. settext (X [0]); int I; for (I = 1; I <= x. length-1; I ++) {TV. append (X [I]);} test = (button) findviewbyid (R. id. test); test. setonclicklistener (New button. onclicklistener () {@ override public void onclick (view v) {// todo auto-generated method stub Sv. scrollto (0, 2222); displaytoast (Sv. getscrolly () + "") ;}}) ;}protected void onscrollchanged (int l, int T, int oldl, int oldt) {displaytoast ("123 ");} public String getinfo (string path) {file; string STR = ""; fileinputstream in; try {// enable inputstream file of file = new file (PATH ); in = new fileinputstream (File); // read all the file content to the byte array int length = (INT) file. length (); byte [] temp = new byte [length]; In. read (temp, 0, length); // encode the byte array with a UTF-8 and store it in the display string STR = encodingutils. getstring (temp, text_encoding); // close the inputstream in. close ();} catch (ioexception e) {displaytoast (E. tostring ();} return STR;} public void displaytoast (string Str) {toast. maketext (this, STR, toast. length_short ). show ();}}