Implementing view recycling with PagerAdapter - android

I'm using the Pager adapter with some ViewPager.PageTransformer to make a stack effect when user scrolls through pages, I'm also trying to recycle my view, My problem is the z order of the view gets messy when I'm using recycled view.
example:
view pager starts with 2 view the first is above second,
user scrolls right -> thrid page rendered, user scrolled right first page destroyed and go to recycle, forth page generate with recycled page, now he(number 4) suppose to be below number 3 , but he is above.
I tried to played with the insertion of the views to the container according to the position of current page and last pages adapter asked to instantiate, but it didn't help
I also tried playing with off screen page limit without any success, every few swipes a view that suppose to be below a view comes above him.
Any suggestions?

Related

RecyclerView LayoutManager - force to keep a view even if not visible

I am animating views between two RecyclerView. The first one is something like a list of folders showing the first item as cover, clicking it opens a new view showing the folders content animating the cover to the first item. Clicking back animates all visible views back to the folder where they came from (the cover being the top most view). This looks great as long as the opened folder shows the first item. If I scroll down the first item will be offscreen and the back animation does not look that good anymore because the cover view is not animated (I'm only animating all visible views currently).
What I think would work is following: the LayoutManager could position the first item at a position shortly offscreen and keeps it as a special view in it's pool so that u always can access the first view and when I animate back to the folder view I can animate the cover in addition to all other currently visible items ( the cover will be animated from top of the screen).
This means I need following:
the LayoutManager must handle the first item as a special one that is not recycled (I may need it any time for the back animation)
the first item must always be layed out (either at the default position in the list, if it is visible or offscreen directly above the screen), again because I may need it at any time for the back animation
Can someone help me where to start here? I think this is possible with extending the LayoutManager but I don't know where to start...
Have you tried the following?
recView.getRecycledViewPool().setMaxRecycledViews(TYPE_XXXX, 0);

Nested view pager (VERY STUCK)

I am using a view pager in a recycler view cell, which is swiped to reveal a checkmark image. Outside of this, the recycler view is contained in a fragment which is located inside of another viewpager. What I want to accomplish is, after the cell's viewpager finishes, it begins to drag the view pager containing the fragment. I have been working on this for two days and have not reached any solution. It works fine if I lift my finger between swiping the view pager in the cell and then swiping the screen again to swipe the fragment's view pager. However, I want this swipe to be possible without having to lift a finger off the screen. A good model of this is snapchat's swipe to message views. Any help would seriously be appreciated. i do not know what to do. I can provide code, but it's fairly complicated and messy.
The images below are the current app I am trying to execute this behavior in. They are for testing purposes of course. Image 1) is before nothing is swiped. Image 2) is after the cell's view pager has been swiped, and Image 3) is after the fragment's view pager has been swiped. What I want is for there to be no need to touch the screen twice in between images two and three.
best solution is to find a view that does the swipe effect without a pager
cause this is a lot of nested views
I've used one before that has done the job
check this library I used it to implement a row with a swipe to show call button and was inside a tabbed activity didn't have any issues
https://github.com/daimajia/AndroidSwipeLayout
goodluck

RecyclerView jump when item size changes

I have stumbled upon a problem regarding the RecyclerView. The situation is as follows:
I navigate from one Activity to another, the second one having a RecyclerView
The second activity reads an index out of the Intent and jumps its RecyclerView to that position (so it may "start" in the middle, from the user perspective)
The RecyclerView houses a list of news, each one having a network-obtained thumbnail
The thumbnails are obtained using Glide, with a placeholder (so a View inside a ViewHolder is at first inflated with height X, which may change after the thumbnail is obtained)
Now the problem is that when the user scrolls up from the item they started up, the ViewHolder is created and Glide makes a request for a thumbnail. It results in the list item having some height and changing it a second later, after the thumbnail is obtained, which in turn results in a nasty "jump" (because of the size change). It only happens 3-4 times, until enough ViewHolders get created to handle the whole RecyclerView.
Any idea how to prevent this? Ideally I would like to make the item above current to expand upwards.
I already tried making the items stack from the bottom, but it does not solve the issue, just makes it happen for the below items instead of the above ones. Also, I can not and don't want to predict the size of the obtained thumbnail.
I would use a place holder image in the Recycled View. And replace that image when it becomes available (downloaded).
This only works of course if you know the size of the tumbnails.

How to scroll a view above a list view with the list view (Not with header views....)

So to be clear, I can solve this with a header view and trickiness, but I'd rather not.
I'd like to have a set of tabs (which also contains some profile information) above a view pager, which could have multiple pages, where each page has a list view. I'd like when you start scrolling initially, that the above tab / profile view will move with the list view (so if you try scrolling the list view, the area above scrolls up) and once the listview is scrolled down until it is at the first item, that the above view starts to scroll back into view.
This is not solveable with a header view, as far as I can tell, without stuffing this profile / tab view into the header of every list view the view pager holds, and to keep them in sync (which just sounds silly).
I feel there's a way I can make use of onInterceptTouchEvent with a custom layout / scrollview of sorts, any tips on doing this?

ViewFlipper on swipe, animate to next page but refresh the current view with new content?

I am trying to make a small dynamic book on Android.
I currently have a viewFlipper and gesture detector to swipe between the different pages in the book. This works ok if it is a fixed number of pages to a book, but I want to make it dynamic and also memory efficient by saying:
-create a linear layout with a scrollview, put this into the view flipper
-load content to that view
-on page swipe, animate to next page view but refresh the linear layout and load page2 content..etc
-on page swipe to go back a page, refresh view and load that page numbers content..etc
is there a way of doing this? instead of creating a lot of pages and overloading the memory?
A good solution would be to use a ViewPager with your own custom PagerAdapter. In the OnPageChangeListener you would load the next piece of content and then call notifyDataSetChanged() on the adapter.

Categories

Resources