I'm trying to create a layout manager similar to ViewPager, but I'm not sure about what the best way to implement it is.
Basically I want my views to look like this:
From there I want to transition to other views when the user swipes from any of the numbered rectangles on the sides. So, say, if the user swipes from view number 3 and to the left, I would like to transition to the following view:
Ideally, I would like the transitions to be similar to how ViewPager works (i.e. I want the transition to interact with your finger so that the transition progresses back and forth when the user moves his finger from left to right).
It seems like I will need to implement my own version of ViewPager, I'm just not sure how to go about doing this. I only need to handle a small number of simple views so I can probably get away with caching all of my views for better performance.
I know how to implement the code to detect the swipes and where in the view the swipe started, but I don't know what the proper way to implement the view transitions is and how to handle the states of all the different views.
Any pointers are greatly appreciated!
Thanks in advance.
Related
I want to create my own version of ViewPager2 so that I can control the animation design and orientation capabilities. Basically, I'm trying to have a scrolling up and down load new users while left and right would be more information about that user.
I tried using custom animations with swipe gestures, which works exactly as I wanted, except I don't get the control of dynamically animating the swiping direction. Essentially, it still works like a button animation - you might swipe in the direction you want but the animation speed/feel/etc is always the same animation vs. ViewPager2's ability to move with the gesture.
I experimented with OnDragListeners which do give me the "Tinder card movement" animation effect but I don't want to allow for animations in all directions. I was able to use a ViewPager2 for the horizontal direction while using the OnDragListener to override the swiping (using OnLongClick). When you drag up or down it has the same issue of the transition animation being the same speed/feel/etc everytime instead of the nice ViewPager2 slide on touch effect.
I only need 4 fragments for each user so my next idea was to try a horizontalscrollview in a recyclerview but that's working either.
Any suggestions for an approach I might not have considered?
Here is what I wish to implement..
A slider like thing...
Say My app is a game with 4x4 array of level buttons in each screen
and there are totally 3 screens...
The user should be able to swipe his finger from right to left and the
slider should "slide" to next 4x4 set of levels...
Just like what the phone functions while we open apps from homescreen. And if the user swipes his finger from right to left and there are no levels to the left, the slider should bounce back...
So... What I ask is which layout/view/class to use to implement such a slider?
Also, plz inform me how can I implement such a slider which switches between tabs as well (each tab containing different layouts).. I hope I made myself clear...
As i understand you can use:
gallery and for each row create your own viw
ViewPager - like in android market (slide between view)
All of this approaches uses adapters and listeners - you can find a lot of examples in internet. I think in your case viewPager is mor useful, because as i understand you want to have many different views.
I've made an activity that looks a lot like the level select screen from angry birds: there is a grid of button, and you can scroll through pages of them by swiping right or left.
I built it by creating a layout of the buttons, and then adding those layout to a Gallery view.
The problem is the animation is jerky, even if you swipe extra slowly, the content jumps ahead. Even when you fling the gallery page, it skips and jumps along its way to its destination.
I am wondering how to fix this: Maybe the complex layout it making it non responsive during the inflate?
Do you know how to fix this, or of a good way to do a workaround using some other approach that will let me have 3 or more screens smoothly swiping from page to page?
You should be using ViewPager. This is available in android support packages. Gallery Widget will not be smooth if you add components into it which has a lot of touch actions.
http://android-developers.blogspot.in/2011/08/horizontal-view-swiping-with-viewpager.html
i've now got the listview and it's touch actions and swipe actions working. But now i'm not sure how i can implement a swipe effect, like it's in the twitter app.
I've found in the internet that it's possible to animate 2 views with a viewflipper, but is it possible to animate two layouts in the same way?
Anyone out there, who knows how i can implement such a function?
The only thing i want is to switch the ListViewsItem layout with a swipe.
Simple, set both the item views in 2 separate thread and then start both of them.
The views are not cached in a ViewFlipper. Is there a way wherein we can get an image of the view and show it to user so that he sees the Ui as we see on Home scrren(when we swipe the previous view also moves along and when we lift our finger, only then the next view is shown completely.)
What I want to do is that when the user starts moving his finegr on screen, the view should also move along(create an image of view).
I am not getting to do this, as when we swipe the present view goes and next view comes, we do not get both visible when we r moving our finger on screen.
Please if anyone gets what I am trying to do, do help me.
Thanks,
Farha
It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout and after in or out animation is executed, other views' visibility is set to View.GONE to hide them from showing up under/over your current View.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()), on MotionEvent.ACTION_MOVE they perform animations manually and on MotionEvent.ACTION_UP snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView.
You have to figure out a way to recycle your views, like you would with a ListView and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.