Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. //回滚到顶部
  2. public void scrollToTop() {
  3. if (null != adapter && adapter.getCount() > 0 && null != listView) {
  4. //强制停止ListView滚动
  5. listView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0));
  6.  
  7. //如果item过多,则先停在某一项上
  8. if (listView.getFirstVisiblePosition() > 8)
  9. listView.setSelection(8);
  10.  
  11. //延迟一段时间后回滚
  12. new Handler().postDelayed(() -> {
  13. int h = -(listView.getFirstVisiblePosition() + 1) * Constants.screenHeight;
  14. listView.smoothScrollBy(h, 1500);
  15.  
  16. },100);
  17.  
  18. //延迟显示topbar
  19. new Handler().postDelayed(() -> {
  20. if (!isTopbarShow) {
  21. animTopbar(true);
  22. isTopbarShow = true;
  23. }
  24. }, 300);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement