Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //回滚到顶部
- public void scrollToTop() {
- if (null != adapter && adapter.getCount() > 0 && null != listView) {
- //强制停止ListView滚动
- listView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0));
- //如果item过多,则先停在某一项上
- if (listView.getFirstVisiblePosition() > 8)
- listView.setSelection(8);
- //延迟一段时间后回滚
- new Handler().postDelayed(() -> {
- int h = -(listView.getFirstVisiblePosition() + 1) * Constants.screenHeight;
- listView.smoothScrollBy(h, 1500);
- },100);
- //延迟显示topbar
- new Handler().postDelayed(() -> {
- if (!isTopbarShow) {
- animTopbar(true);
- isTopbarShow = true;
- }
- }, 300);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement