Nested view pager (VERY STUCK) - android

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

Related

Sliding Card Design

I am looking for some ideas on how to best achieve this effect. I have two fragments, one containing the map (and all controls) and another fragment that contains my RecyclerView to display the results. In my activity layout I would like to position my map and list fragments exactly how it is shown in this video. The map fragment shall stay aligned with the topmost edge of the list unless the user is actively scrolling the list upwards. The video I recorded should demonstrate what it is I am trying to achieve.
From an explanatory standpoint, I need view and layout ideas. I have already implemented all the necessary callbacks for all user interactions between the two fragments and the activity. One item in particular I am most interested hearing feedback on is how to align two views and then have the lower slide over the view when the user starts scrolling. Notice how the list (when showing) will not scroll downward.
One method I can suggest is to have both the map and the ListView in the same fragment and try this. It's the sliding drawer animation in Play Music.
For the part where touching the map shrinks the list view to a bar on the bottom. I suggest you create animations in the listView to shrink and to expand and call them on event Down and Up respectively. Here is the MotionEvent.

Implementing view recycling with PagerAdapter

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?

How do I implement such a layout?

Photos in this layout can be swiped left and right, and swipe should be 'intelligent', like switching between photos and NOT like just horizontal scrolling of photos.
2 implementations that come to my mind:
HorizontalScrollView (but swiping is dumb)
ViewPager (but there is no way to see adjacent photos)
So, basicly I need a ViewPager for photos that can show adjacent photos.
Is there a robust solution for this?
For cool swiping action viewpager is the best. And you won't have problems with memory. BUT I have no idea how to make view pager part of listview.
If you have final number of items you can use Android Gallery widget which is deprecated since api 16 but does exactly what you need, the main problem is that it cant reuse gallery items inside the adapter.
You also can try this:
Horizontal list view
I have used TwoWayView to implement my layout.
It's better than HorizontalView, cause it re-uses views (like ListView).

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.

Android: Next/Previous fling that sticks to the finger similar to Home Screen

I want to give my app a nice touch by allowing users to slide the page left or right instead of just using next/previous buttons (similar to the home screen).
What is the best way to do that? I assume I would have to override one of the Activity.on... methods and that I would also have to put my page's main View in a ViewGroup that allows me to shift pages left and right.
ViewFlipper is your friend!
Here you can see a nice video of the ViewFlipper in action and also a very good tutorial:
http://www.inter-fuser.com/2009/07/android-transistions-slide-in-and-slide.html
The solution is even easier these days with the release of Compatibility Package r3. You can download here: http://developer.android.com/sdk/compatibility-library.html
It includes
ViewPager: A ViewGroup that manages the layout for the child views, which the user can swipe between.
PagerAdapter: An adapter that populates the ViewPager with the views that represent each page.
and Fragment versions of those, if you are that way inclined.
The pager code is compatible back to API version 4 (1.6), and I just implemented a dynamically generated viewPager coming off a dynamically generated ListView in about 2 hours. I'm a novice, so this is definitely the preferred path.
There is an example app here: http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html
If one wants to flip between two activities perhaps one can apply this animated transition:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
finish();
//transition using XML view animations
overridePendingTransition(R.anim.slideinfromright, R.anim.slideouttoleft);
Use GestureDetector to detect if the touch event is a scroll.
If the first event to the first call to onScroll is ACTION_DOWN then you should see if it was a dominantly horizontal scroll. If so then your scroll is started and you should shift the absolute position of the view that fills the page.
For non deprecated absolute positioning, see my answer here Android: Alternative to AbsoluteLayout (I really do need absolute positioning)
You will want to be cautions of whether you return true to consume the touch events or not.
GestureDetector does not have a callback for scrolling having stopped. You will have to check if there was an ACTION_UP before you call GestureDetector.onTouchEvent and if there was an action up and you did have an unfinished scroll then you should set the absolute position to the destination location and use a TranslateAnimation to make it look nice moving from current to destination.
Edit:
GestureDetector did not work well at all if the child views also wanted to respond to touch events. I ended up creating a subclass of FrameLayout (one of the most basic layouts and the closest thing to a non intrusive parent view) and overriding dispatchTouchEvent. I just took all the events and did the detection myself.
cant we use Gallery view here?? with the adapter the whole page can be inflated inside gallery view adapter getView() and it will manage the left right scrolling perfectly.

Categories

Resources