由于在低版本的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);
}
}
这样就能够解决不同的版本