I apologize beforehand, I do not have any code examples as I am completely in the dark for the solution to my problem. I want to know, how can I scroll the last item of a list to the top position of the recycler view?
By default, if all items are displaying, and scrolling is not necessary, then you can no longer scroll to see more items. The conflict with this is that I am updating information on a separate view based upon the top most item.
Any ideas for this? The only thing I could think of was to add arbitrary, fake empty data so that I can continue scrolling. Thanks in advance
UPDATE: The best alternative solution other than dummy data is to add padding to the RecyclerView. If I add paddingBottom, you do not see the empty space until you scroll to the last item. But the padding has to be precise to force the last item to the top position. So even this is flawed.
<android.support.v7.widget.RecyclerView
android:clipToPadding="false"
android:paddingBottom="300dp"
android:id="#+id/rv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:scrollingCache="false"/>
Ok, I was able to get this to work. First I measure the size of the item in the adapter in onBindViewHolder
holder.llWrapper.measure(0,0);
I getMeasuredHeight() from that and pass that back from my Adapter to my Fragment. I then measure the recycler view height. I subtract the height of the recyclerview and the item and the remainder is the amount of padding I need to set bottom to the recyclerview
rv.setPadding(0,0,0,padding);
This is the best I can come up with. Cheers!
Related
I have a recycleview that I like to go past the last element when I scroll up. The reason I need to do this is that I have a floating button that if I don't go past the last item, the floating button covers the right part of the last item. I have seen this done in apps such as WhatsApp (see screenshot).
My approach has been to add two empty items to the end of my list and then set visibility of views based on if the items are empty or not. I feel this is more a hack and I was wondering if there is a better way around this.
Below is a screen shot from WhatsApp where at the end of the list, the list scrolls further.
Thanks in advance
There is not need to add two blank items to recyclerview. It may introduce bugs as well while adding new items to the recyclerview. You just need to provide paddingBottom to the recyclerview equal to the height of floating action button and set clipToPadding = false to the recyclerview.
I want to display a list without scrolling vertically. if list height greater than the parent list must start from the next column. if column fit to the parent it must scroll horizontally. Image shows what I want. please help me to solve this problem
In that case you can use a constraint layout. But the logic to break the list should be implemented by you when binding the adapter with the data and view. Recycler view will be a good container. I hope this sheds some light.
I have Horizontal cyclic ReacycleView. but I want in recycle view's middle item(ImageView) height be greater as compared to other side items.
Recycle view items
That means if any item in the center of RecycleView, it's height should be greater in RecycleView itself.
You can use a different layout for your middle item by implementing getItemViewtype() in your adapter. Similar question and answer here should point you in the right direction.
I created a sample app with this functionality and here is code.
Let me know if you need some explanation.
You need to create A custom layout manager and Item Transformer
CenterLayoutManager
Repository
ScaleTransformer
I am trying to make a horizontally scrolling grid. It has two rows. The second row is offset (by half the width of one item, but that is trivial to calculate and doesn't matter here).
I am currently using RecyclerView and the GridLayoutManager from https://github.com/antoniolg/RecyclerViewExtensions/tree/master/library/src/main/java/com/antonioleiva/recyclerviewextensions
However, the offsetting is proving extremely difficult.
It should end up looking like
Does anybody have any suggestions for making the second row staggered like in the picture above?
Use StaggeredGridLayoutManager with an ItemDecoration which adds the offset to the item at adapter position 0. You'll get the desired output. (via getItemOffsets).
Alternatively, instead of an ItemDecoration, when onBind is called, you can set the first item's width such that it will include gap on left.
If your data set changes, don't call notifyDataSetChanged which will reset the historical calculations in SGLM. Instead, use detailed notify events like notifyItemRangeInserted so that SGLM will be able to recalculate layout without resetting positions.
I don't know if you're still working on this, but my approach would be to render the items 2 at a time (top/bottom) with the appropriate offset, and then play with your horizontal margins (set them to negative) to create the overlap between item 2 and 3, etc.
You would have to tie OnTouchListeners to the individual items being rendered, not the RecyclerView entries.
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 :)