ListView进行平滑的移动
2014-02-04 16:06
309 查看
由于在低版本的Android中是不支持平滑移动,所以需要用反射机制去解决这个问题
smoothToDes(int smoothDistance,int selection) {
try {
if (Integer.parseInt(Build.VERSION.SDK) > 3) {
Method smoothMethod = ListView.this.getMethod("smoothScrollToPosition",new Class[]{Integer.class});
Object[] methodArray = new Object[1];
methodArray[0] = Integer.valueOf(smoothDistance);
smoothMethod.invoke(ListView.this,methodArray);
} else {
setSelection(selection);
}
} catch(Exception e) {
setSelection(selection);
}
}
这样就能够解决不同的版本
smoothToDes(int smoothDistance,int selection) {
try {
if (Integer.parseInt(Build.VERSION.SDK) > 3) {
Method smoothMethod = ListView.this.getMethod("smoothScrollToPosition",new Class[]{Integer.class});
Object[] methodArray = new Object[1];
methodArray[0] = Integer.valueOf(smoothDistance);
smoothMethod.invoke(ListView.this,methodArray);
} else {
setSelection(selection);
}
} catch(Exception e) {
setSelection(selection);
}
}
这样就能够解决不同的版本
相关文章推荐
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- 完美实现Android ListView中的TextView的跑马灯效果
- 解決Linux下Android开发真机调试设备不被识别问题
- [Android]在代码里运行另一个程序的方法
- [软件咨询]WPS2012正式版已发布 金山Office移动版4.0发布
- Android笔记-Linux Kernel Ftrace (Function Trace)解析
- 鼠标触发移动的分层菜单 层菜单moveMenu
- android USB如何修改VID具体实现
- Android增量升级的方法和原理详细介绍
- Android Mouse实现过程详细笔记
- 深入Android Browser配置管理的详解
- Android Mms之:深入理解对话列表管理
- JavaScript Select和Option列表元素上下左右移动
- Android APP与媒体存储服务的交互
- android 多线程技术应用
- Android之采用execSQL与rawQuery方法完成数据的添删改查操作详解
- C#中无边框窗体移动的简单实例
- c#文件的复制,移动,创建(实例代码)