I have list of elements in scroll view. When clicking the element, I need to load data from server and inflate it in the clicked view. The data I fetch from server has variable heights. So I cannot fix the view height.
My problem is,
1- I click a view to fetch data.
2- I will be showing progressbar during server fetch.
3- I scroll down to view other data. In the mean time, if the the server fetch is success I will set the data. It will automatically adjust the scrollview. Since the scroll height is changed, the data I am viewing suddenly scrolls down.
I need to lock the scroll to the content I am viewing. I tried this solution, Stop ScrollView from setting focus on EditText but this is not working during scroll.
Pleas advice. Thanks in advance.
Related
I have a list of elements in a recycler view that are generated dynamically using data binding. Each element has a bottom view that is initially set to View.GONE, however once a user clicks the element and the view is expanded, the recycler view automatically scrolls back to the top of the list. Conversely, if the view is expanded and then clicked again to collapse, the recycler view scrolls to the top of the list again. I have tried keeping track of the ID's of the elements for the adapter (again using data binding), setting focus to the child element when they expand or collapse, and using binding adapters to animate the expand/collapse itself.
My suspicion is that the adapter in the recycler view is receiving a onNotifyDataChanged() alert when the height of one of the child changes, rendering an additional view (still inside one of the children though, not a separate child in the list), and automatically scrolls to the top. Is there a way to override this? Does anyone know what else might be causing the list to snap to the top when one of the elements is clicked -> expanded/collapsed?
So I found the solution to my issue in case someone encounters something similar. I actually ended up finding this answer: RecyclerView notifyDataSetChanged scrolls to top position
and the second solution involving the staggered layout manager was the route I went with, since I want to be able to wrap the content. My suspicions were correct that it had to do with the changing height of the elements in the recycler view. The expandable item's parent wrapped content, so the recycler view was forced to recalculate the size of the item once the expandable portion appeared/disappeared (at least that's what I got out of it).
I have a recycler view that loads more content when users scroll to the bottom.
To scroll to the bottom once, I can use something like:
recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1)
Is it possible to continually scroll the recycler view until it reaches the very end? The recycler view does not have thousands of items so it'll only have to scroll a few times before it reaches the end.
You can easily do this by the following logic:
Scroll your Recycler view to bottom once as per your needs.
As per your response from the server maintain a value which tells if there is more data available for the user. Value can be like 0 or 1.
0: No more data is available for the user.
1: More data is available for the user.
If more data is available for the user then after the data is set on the screen again scroll user to bottom of the Recycler View else don't scroll.
Tip: Maintain a delay of about 200-300ms or 500ms(fail safe) after your data is set on the screen and before scrolling to bottom to avoid any errors or crashes.
Hope this helps.
My layout is a bit complex.
I have a SwipeRefreshLayout in which I host a ListView. Whenever the user drags the Listview's top, the SwipeRefreshLayout performs a refresh. I also listen for the last visible item of the ListView to load next page of records (Endless scroll)
In the list's adaptor I have 2 views that I am using. The first one will only be visible in first row, the other view will remain the same for all other rows.
What I want to achieve:
On top of the row with position = 1 I want to have a sticky header. This means that when I scroll Up, the header will scroll to the top of the screen and will remain in there.
This sticky header will only be at one row
if possible I'd like to use a simple implementation as my layouts and adapters are already complex enough.
Waiting for your suggestions.
I didnt quite get your question the first time, heres the answer attempt round 2.
In your layout add an empty viewgroup (whichever you prefer, though linearlayout seems to work just great), add a scrollListener to your listView and check the position of your sticky view. If its top anchor is below (meaning its visible in the listview) the top of the screen you set the viewgroup visibility to gone, if the top anchor is either touching the top of the screen or below it, you add that view or one just like it to the viewgroup and set its visibility to visible.
You can adjust the position 2 view visibility accordingly to allow for this change to appear seamless. Can help you a bit more once you have some code and are on your way with this change.
Hi,I am new to android.my requirement is when user scrolling the scroll view,based on scrolled height i want to change images on screen. for this i want the event which will call immediately when scroll is changing,and once user reach end position i want set it to first position programatically. it is continuous loop.
You may use the listView instead of scrollView. So you can use onScrollChangeListener.
I have a listview which will be populated more than 3000 items at a time. Each item has an imageview whose image I have to fetch from server. I want that when user scrolls and finish completes, listview load images of only those views which are visible on screen and also deletes images of those rows which has been scrolled up and down (not visible) on screen so that their images can be redownloaded when they get come on screen because I cannot keep images of all data due to memory limitations.
ListView already reuses views that are not visible, so no need to delete them afterwards, but you could optimize this by adding an scroll listener to the list and don't download images when the user is flinging, only when the scroll is stopping.