ViewPager Partial Swipe - android

so I'm considering making a UI that consists of a list with expandable sections. I've read that the ExpandableList design is being phased out, so as an alternative, I am thinking about using a ViewPager that can partially swipe. What I mean by partially swipe is that the UI will consist of 3 columns, each column expanding relevant items in the column to its immediate right. When an item is selected in the very right most column, all the fragments will shift to the left and a new column on the right will display the next level of relevant items. All the while, a PagerTitleStrip will give the title of right most column.
In my research, I didn't even really know what to search to find information, so if anyone has any idea how to go about this, it would be greatly appreciated!

I realize this is a very old question, but here's my answer anyway.
Check out ViewPager.PageTransformer.
You can handle complicated behaviors like partial scrolling, position of each view, etc. on transformPage(..). This can be set to the ViewPager using viewPager.setPageTransformer(..)
An alternative could be using a RecyclerView with the total width of the three columns instead of a ViewPager and use smoothScrollToPosition(..) to the correct column when the next one expands. (With this you might have to disable manual scrolling on the RecyclerView like this

Related

Properly exchange items between multiples RecyclerViews

Being objective, my goal is simple (or not), drag a recycler's item to other one in my activity.
The scenario is the following.
I have a list of items, let's call them sections, and inside a section another list of items, of another type, the elements.
I want exchange the elements between the sections. The list of sections isn't fixed, can be changed adding and removing a section, but hasn't any movement behavior. The elements also can be added and removed from a section, but have this reorder approach.
I've found some strategies with fixed "section". Here is an example. This one uses drag and drop to make the exchange. But it's too simple. For example, don't consider the need to scroll recycle when the dragging reaches bottom or top of visible elements. That's because it has only two lists. Does Drag and Drop have this behavior, forcing the scroll?
Is there any way to do this using the ItemTouchHelper? If so, how would it be? ItemTouchHelper seems better, 'cause considers the scroll problem and has a more intuitive reorder animation.
If you think of a better approach than using recyclers, feel free to indicate such strategy to me.
You use drag and drop for the dragging and dropping, the scrolling and such you'd have to make yourself using the appropriate events in the OnDragListener.

RecyclerView vs ViewPager

Currently, I am exploring the option of displaying data from a database by swiping left to right and also allowing users add and remove data from any position in the data array.
I found out that there are 2 possible solutions to do this. One is a RecyclerView with horizontal scroll and the other is a ViewPager with a FragmentStatePagerAdapter .
Which is more efficient? In terms of Memory usage and Ease of implementation?
Thanks.
I would say they are comparable in terms of memory usage and ease of implementation. Where they differ most is in the interaction they provide to the user.
ViewPager is designed to show one item at a time. The visible item takes up full width of the ViewPager. You can only swipe one item at a time and scrolling always snaps to showing one item in the centre – you're never left in an in-between position partially showing two items.
RecyclerView with a horizontal layout manager on the other hand can have items of any width – you could be showing many items at once or you could have items wider that RecyclerView's width or you could match their widths to mimic ViewPager. You can freely scroll – you are not limited to one item width or RecyclerView's width, you can do a fling gesture to scroll big distances. And there's no snapping – when the scroll finishes there's no aligning items to the centre or any of the sides.
As you see there are a few differences. I would recommend you to choose your widget based on the UI you want to achieve. If you want ViewPager's behaviour (one item visible at a time, swipe limited to one item and snapping to show the full item) then go with a ViewPager. It's possible but not trivial to replicate this behaviour using a RecycleView. I would definitely say it is way more difficult to use RecyclerView if you want to make it behave like ViewPager. Conversely it's pretty much impossible to customise ViewPager's behaviour, so if that's not what you want then you definitely should use a RecyclerView.
In term of ease of implementation (this is just my own opinion),
ViewPager is good for displaying the list of data that is not required often add and remove since PagerAdapter can't notify each specific item that it is removed or added it can only call notifyDataSetChanged() which notify that all set of data has been changed. Therefore, it is hard to handle the animation when the item is added or removed.
While in RecyclerView, RecyclerView.Adapter has methods like notifyItemInserted(int position) or notifyItemRemoved(int position) to notify that specific the item is added or removed and, the animation when item is add or remove is already handle when you called those method.
Moreover, right now it is very easy for RecyclerView to mimic the ViewPager behavior by using SnapHelper. There is PagerSnapHelper, and the behavior of ViewPager can be obtained with just a few lines of code. You can contact me if you want the code.
There is no comparison between this two. basically in ViewPager you can scroll only one item at time (either left or right), and in RecyclerView you can scroll to any index. it all depends on your requirements how you want to use it. you need to develop fragments for ViewPages, one for each page. as in RecyclerView you will have a item which will be used by adapter. both of them are easy to implement. there are numerous examples on both of them, you can have a look and get started.

Android Swipe Dismiss multiple items for RecyclerView

I will need to create cards layout mimicking cards found in Google Now. To do so, I've used a RecyclerView and each row as both the header and item. Pretty skeptical with this approach however.
The problem I'm facing is to mimic the swiping behaviour. Swiping at the header will also move the entire card (header + items) together.
To do so, I managed to edit the SwipeDismissRecyclerViewTouchListener and the adapter to remove the affected items. But after that, the visual would get clunky whereby remaining items would have random empty spaces in between or height that does not match.
How and what is the correct way to approach this? Should I instead use another way to populate the cards?

Want horizontal scrolling to stick with columns instead of whole pages (fragments)

I want to show several columns in one Activity. If there are more columns than can actually fit the screen, user should be able to swipe left and right to move among these columns. This can by easily done by ViewPager or HorizontalScrollView.
However I would like the user to see each adjacent columns on one screen.
A picture should better explain my intention:
(to clip or to stick.. don't know what word I should use)
Am I able to make ViewPager or HorizontalScrollView to stick with columns instead of whole pages (fragments)?
Or do you please know of any open source projects that achieve desired behaviour of ViewPager / HorizontalScrollView?
EDIT: I've found out that similar behaviour appears in a few examples of API Demos app!

Swipe Indication for user Android

Suppose I have a ListView displaying exactly 10 rows that is not intended to scroll.
When the user swipes, the next list of 10 rows would be displayed. The bottom of the ListView would say something like "page 2 of 3".
How can I indicate to users that they should swipe to get the next page?
A page indicator might be helpful like you said. I view-pager may be another option. In that case I would use: http://viewpagerindicator.com/
I think you are best off rolling your own solution using a ScrollView and/or a ViewPager
According to a GoogleIO presentation about ListViews, they are coded with many "behind-the-scenes" tricks in order to optimize performance.
When you start trying to modify how they work, then you end up with a complex widget that doesn't make use of its own complexity and optimizations.
Some type of vertical view pager could be good for what you see though.
Reference: http://www.youtube.com/watch?v=wDBM6wVEO70

Categories

Resources