`
ydbc
  • 浏览: 722457 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

Android ScrollView用法

 
阅读更多

今天试着使用了一下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.zip_android_android scrollview_anriod viewfil

    android实用组件scrollview的用法说明,内附代码,可实现滑动效果,给力哦。

    Android平台下使用ScrollView滚动效果代码

    Android平台下使用ScrollView滚动效果代码,详细可以参见博客:http://www.cnblogs.com/plokmju/p/android_ScrollView.html

    Android控件之ScrollView用法实例分析

    本文实例讲述了Android控件之ScrollView用法。分享给大家供大家参考。具体如下: ScrollView滚动视图是指当拥有很多内容,屏幕显示不完时,需要通过滚动跳来显示的视图。 ScrollView只支持垂直滚动。 以下为案例 ...

    Android垂直滚动控件ScrollView使用方法详解

    1)ScrollView垂直滚动控件使用方法 1、在layout布局文件的最外层建立一个ScrollView控件 2、在ScrollView控件中加入一个LinearLayout控件,并且把它的orientation设置为vertical 3、在LinearLayout控件中放入多个...

    ScrollView+LinearLayout模拟ListView

    有时候项目在ListView中需要显示EditText,CheckBox等控件,这样就会出现一个问题,滑动时或失去焦点时编辑信息混乱。...这里提供了令一种解决方法,ScrollView,+LinearLayout模拟ListView完美解决。

    Android ScrollView无法填充满屏幕的解决办法

    ScrollView滚动视图是指当拥有很多内容、屏幕显示不完时、需要通过滚动跳来显示的视图、Scrollview的一般用法如下 以下代码在Scrollview里面放了一个RelativeLayout、并且是设置为Android:layout_height=”match_...

    判断ScrollView是否滑动到最下边或者最上边

    这个代码可以判断ScrollView是否滑动到了最下边或者最上边,同理,HorizontalScrollView也可以...使用方法就是直接用这个自定义控件并实现里面的OnScrollListener就可以了,会自动复写三个方法:上边、下边或者中间。

    Android ScrollView使用代码示例

    用法:在XML文件中将需滚动的控件包含在ScrollView中,当控件超出屏幕范围时可通过滚动查看;ScrollView也提供了一些方法来控制自身的显示情况。   1.ScrollView中包含其他控件 代码如下: &lt;ScrollView android:id=...

    Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法

    主要介绍了Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法的相关资料,需要的朋友可以参考下

    android viewPage使用+水平滑动组件

    android viewPage使用+水平滑动组件 没什么特别的,就是基本的viewPage使用方法DEMO+一个水平滑动。今天第一次接触viewPage,貌似是4.0以后出来的 ,以前多屏幕滑动用的是继承viewGroup自己写,现在google倒是考虑到...

    Android中ScrollView嵌套GridView显示不全解决方法

    Android中ScrollView嵌套GridView显示不全解决方法 由于ScrollView和GridView这两款控件都自带滚动条,一起使用GridView会显示不全 解决方法:自定义gridview 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持! ...

    Android使用TextureView播放视频

    android中使用TextureView播放视频。TextureView使用变换(平移、缩放、旋转等)方便。也可以放在ListView或者ScrollView中,使用UI控件的一些特性比如View.setAlpha()。 博客地址:...

    Android开发案例驱动教程 配套代码

    3.3 使用Android SDK帮助 23 3.3.1 Android SDK API文档 23 3.3.2 Android SDK开发指南 24 3.3.3 Android SDK samples 24 3.4 使用DDMS帮助调试程序 26 3.4.1 启动DDMS 26 3.4.2 Device 28 3.4.3 Emulator ...

    Android自定义scrollView实现顶部图片下拉放大

    这几天有空,所以重新使用自定义scrollView的方法实现这个效果。原理和之前的基本是一致的,所以也不多说了,直接上代码。 package com.example.myapplication.dropzoom; import android.animation....

    Android布局优化之ViewStub控件

    当ViewStub使用在布局文件中时,当程序inflate布局文件时,ViewStub本身也会被解析,且占据内存控件,但是与其他控件相比,主要区别体现在以下几点: 1.当布局文件inflate时,ViewStub控件虽然也占据内存,但是相...

    疯狂Android讲义源码

     1.3 Android常用开发工具的用法 10  1.3.1 创建、删除和浏览AVD 10  1.3.2 使用Android模拟器  (Emulator) 14  1.3.3 使用DDMS进行调试 15  1.3.4 Android Debug Bridge(ADB)  的用法 16  1.3.5 使用DX...

Global site tag (gtag.js) - Google Analytics