今天试着使用了一下Android的滚轮,以下是一个小小的测试,读取测试文件,主要是使用scrollTo函数和getScrollY(),程序点击BUTTON按钮,则向下滚到2222处并显示。
main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<? xml version = "1.0" encoding = "utf-8" ?> android:id = "@+id/widget38" android:layout_width = "fill_parent" android:layout_height = "fill_parent" > android:id = "@+id/widget32" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_x = "0px" android:layout_y = "0px" > </ LinearLayout > android:id = "@+id/sv" android:layout_width = "wrap_content" android:layout_height = "wrap_content" 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" /> </ 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" /> </ AbsoluteLayout > |
main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
package 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 /** final public String "/data/data/zy.Scroller/aaa.txt" ; // final String "UTF-8" ; ScrollView TextView public Button @Override public void onCreate(Bundle super .onCreate(savedInstanceState); setContentView(R.layout.main); sv tv String str String[] x "/r" ); tv.setText(x[ 0 ]); int i; for (i 1 ; 1 ; tv.append(x[i]); } test test.setOnClickListener( new Button.OnClickListener() @Override public void onClick(View // sv.scrollTo( 0 , 2222 ); DisplayToast(sv.getScrollY() "" ); } }); } protected void onScrollChanged( int l, int t, int oldl, int oldt) DisplayToast( "123" ); } public String File String "" ; FileInputStream try { // file new File(path); in new FileInputStream(file); // int length int ) byte [] new byte [length]; in.read(temp, 0 , // str // in.close(); } catch (IOException DisplayToast(e.toString()); } return str; } public void DisplayToast(String Toast.makeText( this , } } |