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.
Related
I am developing profile screen using Compose UI, it has sticky scaling avatar as header base on scrolling position of the below list, the avatar will be scaled up/down when the first item of the list is visible, and when the avatar at the smallest size, the list can scroll as a normal list, as below
I am on MotionLayout approach. But can anyone give me another hint ?
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 have a listview with a comments. Comments has different length(from 1 line to 20, for example).
And while I'm scrolling this listview, standard scrollbar increases and decreases, depending of what the comment I'm scrolling in this moment.
Why is it happening?
Maybe this is what you need. Just set it false
setSmoothScrollbarEnabled
I found this online on why this happens. Not sure why Google decided make lists height-agnostic.
If the ListView contains items with variable heights, the ListView has no way of knowing the full height of all the items it contains so the height of the thumb is calculated based on the number of items in the view and the number of items currently visible. The number of items currently visible varies, so the thumb height varies too.
On iOS the equivalent component (UITableView) requests the height of all items from the UITableViewDataSource before the view is shown so the overall thumb size can be known and kept consistent.
Max Howell, Last.fm developer
Why does the scroll bar change its length during scrolling?
I need to calculate the measured height of my views without measuring all views, because these views contain images fetched from the internet. When I measure the views, they download images to memory and I an catch out of memory exception. I use custom ScrollViews, which work like ListViews, display some part of views and when scroll, add to bottom or top.
How can I calculate the height of all my views without throwing out of memory exceptions?
Or how can I make ListView calculate its height before rendering views?
You can use getLeft(), getTop(), getRight() and getBottom() these method's on view. for more information . see following link
http://developer.android.com/reference/android/view/View.html
You answered your own question:
display some part of views and when scroll, add to bottom or top.
ListView does NOT know the heights of items it has not yet seen. It lays out some or all of the items it knows, adds an extra bit of UI at top and bottom to visually indicate that there may be more items, and scrolls that. The total scrollable range for ListView can change as it adds more items.
I am aware that I should decide how many pixels based on density.. not hard coded.
I have section headers and items displayed in a scrollview and I want to scroll to a certain section header (the one for the current date) while making it clear that it is not the top of the screen (show about half of the previous item).
How can I do that? I do not want this automatic scroll to be animated.
With View.requestRectangleOnScreen() you can scroll to show a particular rectangle (the linked method allows disabling animation). You still will have to calculate that rectangle, but once you have the position of the particular child (your header) you can easily do that getting the size of the ScrollView. You could consider the small offset you want in calculating that rectangle or just do a scrollBy() after requestRec....() (the former way is better I think).
An easy way to use a density independent dimension is to define it in xml as a dimension resource.
-- edit: you get the position of the child in parent with getLeft() / getTop().