Android ScrollView用法
来源:互联网 发布:网络电视无线路由器 编辑:程序博客网 时间:2024/05/18 10:07
今天试着使用了一下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
34
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget38"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="0px"
android:layout_y="0px">
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
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 {
/** Called when the activity is first created. */
final public String DEV_FILE = "/data/data/zy.Scroller/aaa.txt";// 测试文件
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);
tv = (TextView) findViewById(R.id.txtView);
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 file;
String str = "";
FileInputStream in;
try {
// 打开文件file的InputStream
file = new File(path);
in = new FileInputStream(file);
// 将文件内容全部读入到byte数组
int length = (int) file.length();
byte[] temp = new byte[length];
in.read(temp, 0, length);
// 将byte数组用UTF-8编码并存入display字符串中
str = EncodingUtils.getString(temp, TEXT_ENCODING);
// 关闭文件file的InputStream
in.close();
} catch (IOException e) {
DisplayToast(e.toString());
}
return str;
}
public void DisplayToast(String str) {
Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
}
}
- Android ScrollView用法
- Android ScrollView用法
- Android中ScrollView用法介绍
- Android中ScrollView的用法
- Android ScrollView用法实例汇总
- Android下ScrollView的用法
- Android控件之ScrollView用法实例分析
- android下拉刷新scrollview的用法pullToRefreshScrollview
- 【ScrollView】ScrollView用法
- ScrollView用法
- ScrollView用法
- ScrollView用法
- ScrollView用法
- ScrollView用法
- android(11)(ScrollView的简单用法)
- android TextView 带滚动条,和ScrollView 用法(暂时觉得ScrollView滑动速度比较快)
- scrollview--android
- Android--ScrollView
- android游戏开发框架libgdx的使用-环境搭建
- javaScript中的call的用法
- 网站系统分布式架构
- ubuntu12.04下解决gedit显示乱码的问题
- Struts2 标签库讲解
- Android ScrollView用法
- Weblogic报错 <BEA-000337> <BEA-101215> Oracle后台大量等待
- 【js】js资料(2)
- 他和她的缤纷颜色
- wince6.0 裁剪问题
- linux内核驱动编程的Makefile详解
- Jmeter HTTPcookie管理器 Cookie Policy
- jvm fatal error 导致tomcat崩溃
- Android Service Binder交互通信实例