I want to detect scroll position of my LazyRow.
For example I scroll 2000px in a LazyRow and then navigate to another screen and come back. when I come back, LazyRow is scrolled 2000px and state is saved correctly. However I need that initial 2000px scroll position. how can I achieve that?
rememberLazyListState().firstVisibleItemScrollOffset
As shown above, LazyListSate only gives firstVisibleItemScrollOffset and not the whole scrolling position.
Update: I want this scroll position to react based on it. As in the image below, I have a LazyRow and an Image together. an example usecase is when user scrolls the list, I want to change image's alpha.
Related
I want a screen to arrange rectangles with drag & drop. Elements can be moved freely, so it's not a grid or list. I think I should use absolute positions.
My main problem is that I need an endless screen (when drag to right, scroll the screen to the right). One solution I found was to set width and height to 10000dp and a 2d scroll. Another way is to resize the container each time the user drags an element.
I need a better solution if possible. Any suggestions?
Resize the container each time the user drags an element out of the current view bounds should be the most performant idea.
By the way you should put some max size limit to the view, otherwise you will run out of RAM fast and your app will crash.
I have a RecyclerView with custom LayoutManager that handles the photo laying out so the result is different in portrait and landscape as you can see in the images below.
Now everything is working fine except for when I handle onConfigurationChanged() callback from portrait to landscape and vice-versa.
I want to save state of recyclerView so when user flips the device I will scroll the recyclerview to the same spot he was before rotating.
If you will notice the photos below, the landscape working fine but when I switch to portrait it does scroll to the last position the user where (notice the red car and it is rationally logical since this is what I wanted) but except for one problem, it looks as if the recyclerview is getting suddenly extra white space at the bottom.
I would like to avoid it and get the recyclerview to the bottom of its content (the red car is not the first item in the data set, I have plenty more before it) without actually taking the user to his last item if the position scrolled to is getting the recyclerview to "expand".
How can I calculate if the scrollToPosition() is "expanding" the recyclerview over its content height ? If I remember correctly it does not happen in LinearLayoutManager or GridLayoutManager.
I only need to know if the position that is laying out has enough space before actually scrolling to it and eventually scrolls to a minimum one that does not gives the white space at the bottom, but I don't know how.
Side note: If I scroll it up and then down again it does stay at the bottom without the extra white space.
I was wondering if there was a way to allow a RecyclerView to scroll even if it does not fill the empty space. For example, in the image below, allow the grid to scroll down so cells '28' and '29' hit the bottom of the screen, leaving an empty space above 1, 2, 3 and 4. I have not been able to find anything on the topic. The RecyclerView I have implemented does not scroll unless the cells go past the bottom of the screen.
I have a list of items in a RecyclerView, which is scalable when pinching, and it currently scales the items fine, with the first list item staying when it is (the far left one).
What I'm looking to do is to keep the centre item pinned in the centre while I scale. I'm hoping that RecyclerView makes this easy for me.
If item is focused, LinearLayoutManager will preserve its position when layout occurs. (L-preview does not do this but L release will have it). This may not be enough for you if you want to keep item's center stable because LLM will keep the items reference point stable. (e.g. reference point is the top pixel of the item if layout is vertical and reverseLayout is false).
As a workaround, you can call LLM#scrollToPositionWithOffset with proper values each time you resize the View.
I have a custom ListView that scrolls down quite a bit. I want a background image that tiles and scrolls with the ListView.
I used the code from this answer but background images are jumpy in that at certain scrolling points the entire thing resets to what is currently the top of the viewable screen. I assume this is because of ListView optimization. How do I get around this if each item in the list has the same height? I don't need the image to load for nonexisting items, I just need the illusion of continuity.
Otherwise, tiling works just fine.