I made header and footer in my RecyclerView using typical solution with viewType in Adapter. It works fine, but I want to hide the footer if all RV items fit inside the screen, when nothing to scroll. Is there any way to know that all items will be displayed without scrolling and say to Adapter not to add footer in this case?
You can get scroll offset of recycler view with this code
recyclerView.computeVerticalScrollOffset();
Then you should check if scroll offset is more than your parent views heigh and do what you want ;)
Related
I was trying to design my screen as of same in Swiggy App. First, it has horizontal recycler or horizontal scroll view.
Second, it has tab bar which will stick on the top once we will scroll up. Third, it has a vertical recycler view or maybe listView showing restaurants.
So, if we have vertical listView, it's very easy to stick that tab bar(view, the second thing on screen) on the top.
You can see an example here: https://dzone.com/articles/creating-a-listview-parallax-effect-with-a-sticky
But in case of RecyclerView, it doesn't have any direct method addHeaderView. So how do we implement this with RecyclerView.
Use getItemViewType method and create three view holders for first, middle and last items.
RecyclerView with multiple view type
I want to scroll a specific item to the top in RecyclerView.
Here is the code I am using,
rvTweets.smoothScrollToPosition(position);
or
linearLayoutManager.scrollToPositionWithOffset(postion,0);
Both the code work when RecycelerView has enough items to cover the complete height of the screen. Otherwise, it does not scroll the desired position to the top.
In my application I have branding footer at the end of scroll on all screens (for screens which have scroll) and static at bottom of the screen when(no scroll).
But I am facing issues to achieve this with screen which has list. I am using recyclerview for showing list. I want to show Branding Footer at end of the recyclerview when it has scroll and it will be visible when it is scrolled at the bottom. This is achievable with Recyclerview with footer.
But when recyclerview does not have scroll (when few items in list), I want footer fixed at bottom of the screen.
Thanks in advance!
The question appears similar to several other, most of the stack overflow posts related to this question point towards the usage of itemdecoration to achieve this (By adding itemdecoration of the desired height)
One way of achieving this would be to determine the height of the recycler view beforehand and then using that information to set the offset for the footer in the itemdecoration associated with the recycle view
This might help: How implement sticky footer in recyclerview
I would like to use horizontall scrolling items in a vertically scrolling Listview.
Note that the items should scroll horizontally independently of the other items, i.e the whole list should not scroll sideways when dragging sideways.
Take vertical scroll first and in that vertical view take a table row and in that row take Horizontal View. Do these as many time as much you need horizontal view in vertical scroll view......
for easy implementation use TABLE and its Rows instead of vertical view
This should be the code for you list-view-item:
<ScrollView
....attrs...>
<!---Your layout---->
</ScrollView>
Use this layout as one row of the list view and this should work well.
Also if you already have a code for the adapter class, you wont have to make any changes to it.
i want to display the listview's scroll item by item, means single item height is equal to listview height, so on listview there is only one item will display at a time, and after scrolling the listview, remaining item will display. But problem is that if i scroll listview, it scroll many items, but i need to scroll only by one item.
in-short listview scroll by many row at a time but i want only one row scroll at a time
please suggest me some tips or method :)
thank you
So if I understand you correctly, you want a 'pager', sort of like, you scroll page per page instead of inbetween every item, right?
I'm using a Horizontal Pager at the moment, it uses a GroupView and measures the scroll amount to snap to the next view in the pager. Perhaps you could write your own GroupView as well calculating the scroll Y values to snap to the next page..
It's not going to be easy, but it's the only way I can think of.
You could look up Horizontal Pager on google and look at the code, and implement it for vertical paging :)