- 浏览: 427110 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
yehuiyan8002:
支持中文查询
快熟查找联系人 -
lehehe:
现成的接口,免费试用,http://www.haoservic ...
天气Widget -
D.Z:
android:focusable="false&q ...
CheckBox在ListView 而导致其OnItemClickListener不会被触发 -
freecode:
碰到该问题,CheckBox的android:focusabl ...
CheckBox在ListView 而导致其OnItemClickListener不会被触发 -
echohfut:
哥们,新博客是不是在墙外啊?不能访问。还有你怎么进行博客迁移的 ...
博客 迁移
文字垂直滚动
[功能]
在以前的文章曾经写过 如何水平滚动 现在说一下垂直滚动
[原理]
1. 设置 ScrollView的控件高度 为定值
2. 如何滚动显示:ScrollView.smoothScrollBy()
3. 如何循环滚动显示 即 当滚到最下面后 会回到最上面继续滚动: 得到最下面的垂直位移 然后通过 ScrollView.scrollTo() 来返回最上面
4. 如何判断是否到达底部:通过 ScrollView.getScrollY() 得到本次的垂直位移 然后与上次该值做比较 如果相等 则已经到达底部 否则 继续往下滚动
[代码 步骤]
1. 现以陆游的诗歌为例 定义布局文件 main.xml 如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Text head! - 钗头凤 之 陆游 唐婉" /> <ScrollView android:id="@+id/sv" android:layout_width="fill_parent" android:layout_height="50dip" > <LinearLayout android:id="@+id/layout" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="钗头凤 陆游"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="红酥手 黄藤酒 满城春色宫墙柳"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="东风恶 欢情薄 一杯愁绪,几年离索"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="错!错!错!"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="春如旧 人空瘦 泪痕红悒鲛绡透"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="桃花落 闲池阁 山盟虽在 锦书难托"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="莫! 莫! 莫!"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="---------"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="钗头凤 唐婉"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="世情薄 人情恶 雨送黄昏花易落"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="晓风干 泪痕残 欲笺心事 独语斜阑"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="难!难!难!"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="人成各 今非昨 病魂常似秋千索"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="角声寒 夜阑珊 怕人寻问 咽泪装欢"/> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="瞒! 瞒! 瞒!"/> </LinearLayout> </ScrollView> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Text tail!" /> </LinearLayout>
2. 得到ScrollView 变量 scroll
scroll = (ScrollView)findViewById(R.id.sv);
3. 开辟Thread TimerLoop 用来定时 并通知 Activity 的 ScrollView 滚动一定的位移
private Handler message = new Handler(){ public void handleMessage(Message msg) { doScrow(); } }; public class TimerLoop implements Runnable { @Override public void run() { // TODO Auto-generated method stub while(true){ loop(500); message.sendEmptyMessage(0); } } } //因为sleep()似乎不好用 所以采用这种方法计时 public void loop(long i){ long j = i; while(j>0){ j = j-1; } }
启动之
public boolean onKeyDown(int keyCode, KeyEvent msg){ Thread loop = new Thread(new TimerLoop()); loop.start(); return super.onKeyDown(keyCode, msg); }
4. 根据值比较结果 来决定是 滚动 还是 返回最上面
public void doScrow(){ int now = scroll.getScrollY(); if(ori == now){ scroll.scrollTo(now, 0); ori = -1; } else { scroll.smoothScrollBy(10, 10); ori = now; } }
emulator 运行截图 (注意2次的字符内容的差异)
1.
2.
done!
评论
8 楼
lenomon
2012-04-07
这里有个关于垂直滚动的方法汇总:android垂直自动滚动
7 楼
lenomon
2012-03-11
看看这个,或许适合你要求 android自定义View-垂直滚动的TextView
6 楼
Cremdayz
2011-11-30
[/b][b][/b][b][/b][b][/b][b][/b][b][/b][b][/i][i][/i][i][/i][i][/u][u][/u][u][u][/u]
引用
引用
引用
引用
引用
[*]
[*]
[*]
[*]
5 楼
io_in_stream
2011-10-11
3Q
4 楼
mitechen
2010-09-17
似乎不能自动滚动啊.只能拖动...
3 楼
gryphone
2010-07-09
kaixuan_166 写道
首先感谢楼主。
楼主的说明有问题:
1、如何判断是否到达底部:通过 ScrollView.getScrollY()…………
View.getScrollY() Return the scrolled top position of this view。
所以楼主其实是在比较顶部位置。
2、scroll.smoothScrollBy(10, 10)
为什么要在x方向上移动10呢,没必要吧。
楼主的说明有问题:
1、如何判断是否到达底部:通过 ScrollView.getScrollY()…………
View.getScrollY() Return the scrolled top position of this view。
所以楼主其实是在比较顶部位置。
2、scroll.smoothScrollBy(10, 10)
为什么要在x方向上移动10呢,没必要吧。
一一回复:
1. 我这么做的原因是: 每次下拉后 getScrollY() 返回值 都不同 而当其到达最下方时候 其值保持不变 所以 我借助于此 判断是否已经到达最下方
2. 哪里?
2 楼
kaixuan_166
2010-07-09
首先感谢楼主。
楼主的说明有问题:
1、如何判断是否到达底部:通过 ScrollView.getScrollY()…………
View.getScrollY() Return the scrolled top position of this view。
所以楼主其实是在比较顶部位置。
2、scroll.smoothScrollBy(10, 10)
为什么要在x方向上移动10呢,没必要吧。
楼主的说明有问题:
1、如何判断是否到达底部:通过 ScrollView.getScrollY()…………
View.getScrollY() Return the scrolled top position of this view。
所以楼主其实是在比较顶部位置。
2、scroll.smoothScrollBy(10, 10)
为什么要在x方向上移动10呢,没必要吧。
1 楼
gaogaf
2010-06-22
又被这两首诗打动一次
发表评论
-
滑动抽屉 另一种解决办法
2010-07-09 17:43 0滑动抽屉 -
Spinner 定制化 增强版
2010-07-09 14:34 2571Spinner 作为下拉选 ... -
ListView 内容之分批显示
2010-06-25 20:38 5861ListView 内容循环显示 大家试想 假如 ... -
MediaScanner 研究
2010-06-23 15:21 3104MediaScanner 之所以拿MediaSc ... -
CheckBox在ListView 而导致其OnItemClickListener不会被触发
2010-06-22 20:55 18880CheckBox在ListView 而导致其OnItemCli ... -
获取Launcher 启动列表
2010-06-22 10:09 3097获取Launcher 启动列表 即 列出所有Launc ... -
PreferenceActivity 全接触
2010-06-19 12:53 9390PreferenceActivity 为了引入 ... -
android src 下载 编译 安装 全接触
2010-06-12 14:44 0android src - download install ... -
Intent.createChooser() 妙用
2010-06-12 11:14 5917Intent.createChooser(ntent targ ... -
SMS管理:收信箱 发信息 编写新信息
2010-06-07 08:14 14364SMS管理 [功能] 1. 收信箱:显示 ... -
求 android 手机 帮忙测试sms服务系统 谢谢
2010-06-05 08:25 1411Hi guys, 最近一段时间没有更新blog 因为一 ... -
流媒体 播放 理论篇
2010-05-28 14:42 2124流媒体播放 之所以为理论篇 因为该篇仅实现了播放功能 ... -
NDK 搭建与HelloWorld
2010-05-19 09:48 3154NDK [前提] 1. Cygwin 用于安装 ... -
自定义字体
2010-05-15 10:49 1164自定义字体: []代码 步骤] 1 ... -
模糊查找 再深入
2010-05-15 09:41 3100模糊查找 再深入 应某位大哥要求 再次对 SQLite ... -
快捷方式Bar + ViewGroup - 自定义
2010-05-09 09:20 2383TabActivity - 自定义 其实 这篇感觉极鸡 ... -
View 拖动&插入 研究
2010-05-09 07:14 3931View 拖动&插入 即: ... -
带图标 快捷键 Menu - 终极版
2010-05-04 20:23 1785Menu 改头换面 扩展如下: 1. 图标化文字 2 ... -
*.gif 解码 - 实践
2010-05-02 18:58 1653*.gif decode 前面已经说过 今天不打算再说了 ... -
*.gif 解码 - 理论
2010-05-01 21:11 1486我们知道Android 默认是不支持*.gif 的 但是 ...
相关推荐
一个用scrollview和textview实现文字垂直滚动的demo。
易语言文字垂直滚动广告源码,文字垂直滚动广告
文字垂直滚动例程!可以自己改成带连接! 哈哈 将就用吧! 呵呵 !
易语言源码易语言文字垂直滚动广告源码.rar 易语言源码易语言文字垂直滚动广告源码.rar 易语言源码易语言文字垂直滚动广告源码.rar 易语言源码易语言文字垂直滚动广告源码.rar 易语言源码易语言文字垂直滚动广告...
易语言文字垂直滚动广告源码。@资源源码站。
仿暴风影音文字垂直滚动广告
本文给大家分享了三种方式实现Android文字垂直滚动、纵向走马灯效果,文中给大家介绍了相关属性及注意事项,需要的朋友参考下吧
仿淘宝首页的垂直滚动文字 基于Eclipse的android工程源码demo
VB在窗口中实现文字滚动,上下方向的垂直文字滚动,在Form1中可自定义滚动的文字内容,由下向上滚动,速度可调,文字颜色可调,在scroltext中实现的文字滚动。为方便实现文字滚动效果,定义了一个VB控件供使用,你...
主要介绍了js实现文字垂直滚动和鼠标悬停效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
在大型的网站新闻公告和友情链接等领域经常有这种文字或图片垂直滚动的效果,下面就介绍一下文字垂直滚动的javascript代码。 javascript代码如下: <!DOCTYPE html> <html> <head> <meta charset...
本文实例讲述了Android TextView实现垂直滚动效果的方法。分享给大家供大家参考,具体如下: 在TextView中,如果文本很长,可能需要实现垂直滚动显示文本的效果。这里需要在XML布局文件中为TextView设置如下几个属性...
易语言文字垂直滚动广告源码
内容索引:VB源码,字符处理,文字滚动 VB中文文字垂直滚动特效源程序,就像电影序幕一样,文字由下而上匀速向上滚动,当然这个方向是由你决定,在源程序时可以修改这个方向参数,这个小程序可以广泛应用到你的VB程序...
内容索引:VB源码,字符处理,文字滚动,字幕滚动 VB文字垂直滚动,很平滑那种,VB新手可以拿来练手吧,挺简单的,内含一个控制,功能扩展性还可以,你可以制作更复杂更有创意的字幕滚动,祝你好运哦。
文字列表无缝向上滚动JavaScript代码,原来的文件上传错了,下错的朋友可以下这个!