Android 里面让ListView滚动有N种方法,这儿列举三种:
我的需求是通过按键让Listview滚动起来,当然这些按键不是通过Android标识接口传输过来的,所以不能通过监听按键事件来实现此功能;
一、方法一:
也是最常用的方法:
listView.setSelection(position);

直接跳转到指定的位置,可以是事件每触发一次,执行一次,形成滚动效果;


二、方法二:
listView.smoothScrollBy(30, 200);listView.smoothScrollToPosition(index);

smoothScrollToPosition类似于setSelection,但setSelection没有动画效果,直接跳转,smoothScrollToPosition是类似于手滑动,有滚动过程,从名字上就是平滑的意思;

三、方法三:
这个方法比较另类,一般用不到,那就是先让listview获取焦点,然后注入上下按键事件:
void sendKey(final int key) {new Thread() {public void run() {try {Instrumentation inst = new Instrumentation();inst.sendKeyDownUpSync(key);} catch (Exception e) {e.printStackTrace();}}}.start();}

更多相关文章

  1. Android解决输入法自动弹出方法大全
  2. android之视频播放
  3. Android(安卓)AsyncTask完全解析,带你从源码的角度彻底理解
  4. Android程序测试(2)——Activity测试
  5. Android(安卓)显示系统键盘搜索按键,实现搜索功能
  6. android 弹出日期滑动选择框,日期滚动滑动选择
  7. Android(安卓)使用Parcelable传递对象
  8. 浅谈Java中Collections.sort对List排序的两种方法
  9. Python list sort方法的具体使用

随机推荐

  1. Android中文语音合成(TTS)各家引擎对比
  2. Android(安卓)tcpdump 抓包
  3. TabWidget/TabHost的两种使用方法
  4. [转」 在Linux上开发Android,装手机驱动
  5. Android(安卓)studio使用androidannotati
  6. Android(安卓)Dialog的四种情况
  7. 开启Android程序时检测网络与GPS是否打开
  8. android Widgets
  9. Mac系统cocos2dx + android 开发环境配置
  10. Android全屏显示的两种方式