Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested scrollview automatically scrolls to bottom

I have a GridView within a NestedScrollView. I have used the code below to resize the GridView whenever the content of the GridView is changed. This works fine, however the NestedScrollView scrolls to the very bottom when I swipe from fragment 3 of the app back to fragment 2 (where the NestedScrollView resides). This doesn't happen when swiping from fragment 1 to fragment 2, oddly. It also doesn't happen directly after resizing the GridView.

How can I repress the NestedScrollView from scrolling to the bottom?

private static void resizeGridView(GridView gridView, int items, int columns) {     ViewGroup.LayoutParams params = gridView.getLayoutParams();     params.height = singleGridHeight * items;     gridView.setLayoutParams(params);     gridView.requestLayout(); } 

The following system methods are called when swiping between fragments: enter image description here

like image 251
Luke Allison Avatar asked Jun 08 '16 01:06

Luke Allison


People also ask

How do I stop NestedScrollView scrolling?

setnestedscrollingenabled set it to false.

What is difference between nested ScrollView and NestedScrollView?

Nested scrolling is enabled by default. Show activity on this post. NestedScrollView is just like ScrollView, but in NestedScrollView we can put other scrolling views as child of it, e.g. RecyclerView. But if we put RecyclerView inside NestedScrollView, RecyclerView's smooth scrolling is disturbed.


2 Answers

Add android:descendantFocusability="blocksDescendants" to the child layout in NestedScrollView

like image 129
Joseph Paddy Avatar answered Oct 04 '22 05:10

Joseph Paddy


If I add nestedScrollView.scrollTo(0, 0); to the end of the onLayoutChanged() method of the GridView the issue is resolved. However, it would make more sense to prevent the nestedScrollView from automatically scrolling in the first place.

Ideas?

like image 37
Luke Allison Avatar answered Oct 04 '22 06:10

Luke Allison