I am using mvvmcross pattern. I have a list of datasets. I am showing only one dataset on the view. When user swipes either left or right, then I need to reload the view to show corresponding dataset.
My dataset is big (around 100), I am afraid to use viewpager, it might be an issue in terms of memory.
I have used the following approach before Android: How to handle right to left swipe gestures, but I wonder how to detect/implement swipe gesture in mvvmcross ?
Swipe gestures are a View concern and are generally not implemented in a MVVM framework. MvvmCross has a Tap gesture recognizer for iOS only.
So since it is a View concern you should look at how this is done natively on Android.
Related
I just want to allow only scroll left in horizontal recyclerview for example. Please help me on that
Best way is to remove other directions item from adapter, which are getting hidden one by one. So when user scroll back ward it will not show up any thing.
I would not touch the data in your adapter (what does the data have to do with a UI business rule?). If you want, you could notify your Repository or ViewModel what views have been "scrolled" but that's a lot of events going up, and state coming down for everyone involved.
You have the tools at your disposal in the form of a combination of:
A GestureDetector (See (the documentation.)
A TouchListener (See (the documentation.)
Your favorite search engine to put these things together.
or perhaps benefit from the somewhat modular approach of RecyclerView:
Using OnItemTouchListener and a OnScrollListener to analyze the events and ignore the ones you don't want.
You could also create your own extended RecyclerView but that's more painful because you now need to change it all over the place you want this behavior.
In any case, your search engine of choice is also a good starting point. But think of this as:
You will need to intercept the touches and flings gestures (as well as other motion actions like "Dpads" and other Accessibility Events that may trigger a "scroll", evaluate in which direction this is headed, and determine if you still want that event to happen.
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.
I'm using the new slide navigation UI pattern in my android app, yet it keeps crashing when I use it with a vertical listview. The listview listener on my main screen conflicts with the slide menu listener, which causes the crash when they both capture the motion events.
I know using two different listeners for motion events isn't recommended, yet many applications use it nowadays (like Youtube and Facebook). How did they manage to do it? Any useful libraries out there that can solve this issue?
If you want to implement list view on the main screen, you would do that using any of the ListViewAdapter. For implementing listView on the side screen when the view is slided you need to implement using ListFragment.
Also, you may refer example in https://github.com/jfeinstein10/SlidingMenu
I cant seem to find the answer to this, mainly because I don't know what it is called.
I am going to expand a few features in my app, currently users can touch and drag to move forward in a list of images. What I want is for the users to "swipe" there finger and then all of these images will move under acceleration and will slowly come to a stop.
Is this a gesture? If so is it the "Fling" gesture?
There are several ways to do so.
Use ListView
Use Gallery
Use ScrollView
Use HorizontalScrollView
Write your custom ViewGroup or View
For the last approach, you have to detect the Fling gesture as you said and handle all the scrolling animations involved.
I'm trying to implement a UI with a scrollable component that has a certain resistance to starting the scroll - ie. that you have to drag it a certain number of pixels before the scroll starts. Is this supported in Android, and if not is it something that can be added? The idea is to allow a scrolling component to snap to certain positions and resist being moved from them accidentally.
Yes, but you'll have to listen to motion events and track what's happening yourself.