这是产品那边刚刚提出的需求,java
实现起来也是挺简单的,分享下给你们。ide
ListView实现是:post
mList.requestFocusFromTouch(); mList.smoothScrollToPositionFromTop(0,0);
原本是直接spa
mList.setSelection(0);
可是这个因为ListView是放在viewpager+fragment中。并且listview又加了headview,致使会有一些细节不符合产品的要求。code
而后就用上面的实现了。blog
ScrollView滑动到顶部get
rootView.post(new Runnable() { @Override public void run() { //To change body of implemented methods use File | Settings | File Templates. // mRootScrollView.fullScroll(ScrollView.FOCUS_DOWN); int[] location = new int[2]; mAdvertise.getLocationOnScreen(location); int offset = location[1] - rootView.getMeasuredHeight(); if (offset < 0) { offset = 0; } rootView.smoothScrollTo(0, offset); } });
rootview就是scrollview.产品