Creating a recycler view with certain requirements. - android

I am trying to create a specific type of recycler view with following requirements:
1) RecyclerView that would show one item per screen (1 row will take the size of screen).
2) When I scroll the recyclerview it should stop scrolling as soon as the next item is visible. (Captures the whole screen).
Please tell me if that is possible or not.

Do you have to use RecyclerView?
Probably you can do that with View Pager.
https://stackoverflow.com/a/22797619

Related

Android RecyclerView scrolls to top when child element is expanded/collapsed

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).

Scrolling to bottom of recycler view

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.

Swipe and tap to enlarge recycler view

I have a recycler view which has its items in a card view. The recycler view gets its data from a sql database within the app . Now I want to implement two features to this recycler view items. First , whenever the individual cards are tapped , I want them to enlarge and display more data and should shrink back when tapped again. It is not like the case of expandable list view where it expands into a child list view. I want the height of the card to increase and just show some more information and buttons. Second I want the items to swipe left . I know there is a feature for that in recycler view , but I want to customise the swipe feature. Swipe from right should be locked , and when swiped from left , It should not go off list completely. It should show two buttons and should go off list only when one of the buttons is clicked. I have been looking , but there is no proper explaination anywhere. Please guide me through this process.
For your first question, set the adapter layout_height to wrap_content and set the buttons visibility to GONE. Implement the OnClick listener in the RecyclerView adapter and set the visibility of the buttons to VISIBLE if GONE and GONE if VISIBLE or use a boolean to alternate the visibility.
For your second question, this might help:
https://www.learn2crack.com/2016/02/custom-swipe-recyclerview.html
How can I make my Android SwipeableCardViews more like the IOS 7 mail app (swipe to show buttons)
https://github.com/daimajia/AndroidSwipeLayout

Adding More than one item in the list view row and navigate them

I want to make the following layout in android. (Image Attached)
There is a list view and each item in the list view can has as many sub items. (One is visible in one row at a particular time), if a person wants to see further items in a particular row, then he has to use arrows provided on the left and right side of the item in the list view. (Image Attached)
On the arrow click, there should be a pager swiping type view and the next layout should come in the row.
I have tried so many approaches to do the same but have been stuck somewhere and have not been able to do the same yet:
Here I have tried all these :
1st Try
2nd Try
3rd Try
4th Try
Can anyone please tell me how to do the same functionality as shown in the figure attached and discussed above
Alright.
Try this, this should work.
Solution 1:
Have Horizontal Scroll view as child in listview, so basically you have s child now with horizontal scroll ability
Add as many as children you want to this scroll views, you can easily adjust layout of childs within scroll view to display.
Solution 2:
Have a ViewFlipper as a child withing listview
Perform the same thing as above, add as many child you want within this flipper
With flipper you get easy hastle free option like which child you want to display by default withing flipper.
Hope it help.

Memory efficient list for android

I have a list of about 100 items. In each list item I need a framelayout with 2 relative layouts. When a button called "Flip" is clicked then one relative layout will flip out and the other relative layout will flip in. And each item has full width of the screen. So, I need to show the item in a horizontal scroll view. Now, I want to keep at most 3 items every moment. When user scrolls to the first item then we have to update the 3 items. The first item will be the 2nd item. And we have to add another item at the front. In this way we have to update the items when user scrolls to the last item. I have tried many ways. I have used Gallery for the horizontal scroll view. And used the onItemSelected method. But, if I scroll the Gallery fast then it crashes. So, please someone help me to implement the 3 items idea.
It sounds like you need a ListView. Is there a reason you are trying to reinvent it?
Also don't you mean a vertical scroll view? Why are using a horizontal?

Categories

Resources