這是產品那邊剛剛提出的需求,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.產品