Closed radubn closed 8 years ago
that would be pretty tricky to do as this view is not designed for a use case like that.
could you give a more in depth explanation (perhaps with some visuals) of what you're trying to achieve?
it sounds to me what you're after is something more like this:
https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf#.qz1pqcnt6
is that the kind of effect you're after?
Not really, I would like to be able to swipe horizontally only. Kind of like a ViewPager.
I tried to use a ViewPager, but in order to be able to match the directions (right = ok, left = not ok) I have to "hack" it a lot, basically having just three items in the ViewPager, something like this: 1 - 0 - 1. The middle one (0) is the current one, and to the left and to the right is the same element (1). And then after swiping, I have to recreate the same three items again - which is noticeable to the user, as the animation does not complete, and the pager refreshes. It's a lot like an infinite viewpager, but with only three items, one visible and two hidden, those two being the same view, so the user is able to view them when swiping.
I hope the explanation is good :)
so is what you want a vertical scrolling list of cards that can be swiped left and right?
No :)
There is only one card visible in the page on the top of the deck, with lots of text description, that needs scrolling up and down to be fully visible. Just one card, nothing like a listview. I would like to be able to swipe only left/right like in a viewpager, but when swiping up/down there would be scrolling in the same card.
So if I swipe left/right the card is dismissed, but if I try to swipe up/down I can only scroll in the contents of the visible card.
Is the explanation better now?
ok i've hacked something together quickly. it kind of does what you're asking, it allows the card deck to sit inside a scrollview.
as soon as you scroll up or down though the card will reset its position it's difficult to work within a scroll view and to implement nicer behaviour may mean making your own scrollview (i'd need to research more)
there's a branch called scrollview-compat. with a quick demo app of the card deck sitting inside a scrollview.
i may clean it up and add an option to disable up and down swiping and merge it back into master eventually. try it out and see if it gets the job done. it might need some polish though.
Thanks. I cannot find any ScrollView in the branch, though.
there's a scroll view in the example app but there's no special scrollview. it should just worth (okish) within a scroll view.
On Thu, Jan 7, 2016 at 11:30 PM, Butiulca Radu notifications@github.com wrote:
Thanks. I cannot find any ScrollView in the branch, though.
— Reply to this email directly or view it on GitHub https://github.com/aaronbond/Swipe-Deck/issues/1#issuecomment-169649001.
ok just for you i've hacked together an even better version that should give you the behaviour you want. I'll push it soon and might merge it into master because it works fairly well.
look at the example app (under the app folder) in the SwipeDeckActivity class to see how to use it. note that you must set a scrollview on the swipedeck so that it can pass the relevant touch events to the scroll view.
give me a moment to clean it up
The difference between the SwipeDeckActivity in the "scrollview-compat" branch and the one in the master is that clicking on the card starts ActivityTwo. Nothing else to look at. Am I looking at it wrong?
yeah i just realised that. don't worry it's coming.
ok it should have actually pushed properly this time, with my new changes. it still needs a bit of a cleanup because it's honestly a bit hacky but it works for me.
Ok, I've tried it. The main layout is a ScrollView, but I need the card layout to be a scrollview. The height of the card is larger than the height of the screen, so it needs scroll to be fully visible.
"[...]I would like to be able to swipe only left/right like in a viewpager, but when swiping up/down there would be scrolling in the same card."
Did I explain it wrong?
oh i figured you wanted the card view to be able to work within a scroll view,
you actually want a scroll view within a card view, is that correct?
Yes, the card's height is larger than the screen.
I managed to do something like that with a viewpager with three elements, like I've said before, but there are too many hacks and I am not proud of the resulting code.
i'll have to have a go at it when i get some free time, feel free to try and change the code to support what you want in the mean time.
Ok, thanks for your time
i made one last set of changes to allow cards that are bigger than the screen. I believe that's what you're after. check the example app and let me know if that's what you wanted.
oh and i would probably set the rotation_degrees to 0 in the xml because it kind of looks funny the way it is :)
OK, I'll try it.
Yes, that's exactly what I wanted :)
However, can it be some minimum distance (about 10-20dp for example) of swiping left or right, before the card moves, but in the meantime it will scroll up/down? If I try to swipe up/down and I do not make a straight line, the card moves slightly to the right or to the left.
So kind of lateral "tolerance limit" for swiping.
Something like (SwipeListener):
final float diff = xMove - initialXPress; final float dx = Math.abs(diff) > 20 ? diff : 0;
Is this ok? :D
Also, sometimes the example is extremely laggy, other times it is ok. In the LogCat I see only this: "com.daprlabs.swipedeck I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread."
Go ahead and put some logic in the swipe listener to do that. you're pretty much right about how to go about implementing it. just remember that you're probably working with pixels in there not dp so do a conversion from dp to px first and work with that number.
as for the laggyness it's something i've noticed but only seems to happen in the emulator and then only occasionally. can you reproduce it on a device? or consistently?
Yes, I see it on my device (Samsung Galaxy S4, Android 5.0.1). The first example worked fine, the last one (with the working scrollview) is awful. I'll look into it, eventually.
Thanks for your time :)
I'm using rather large inefficient images on the cards. i really didn't make the example to be best practice. using something like picasso to put the images on the card would be much better.
Or even better, Glide :)
For the past 3-4 runs, everything runs smooth, without any changes. After I am done with the listener, I'll try it with my own data, I hope it works fine.
Thanks
Hmmm, it should do, if you track down the cause of the intermittent performance issues let me know. It doesn't happen for me on the master version and i'd have to reproduce the issue and profile it to track it down.
Hi, back again. So, even if it would be nice that the ScrollView would be in the card view layout, not in the main layout, I've included the classes in my project, and the main activity is something like this:
< RelativeLayout > < toolbar > < ScrollView > < SwipeFrameLayout /> < SwipeDeck /> </ ScrollView > </ RelativeLayout >
The vertical scroll is not working. Lateral swipe is ok, though. Does it matter if the ScrollView is not the main layout on page, but a child of a RelativeLayout?
without looking at your code it's hard to tell what the problem is, the way i did it was hacky, i basically took control away from the scroll view and scrolled it myself when i got a touch event.
scroll view doesn't really play all that nicely with sub views.
if it's not scrolling when it should be something might be stealing the touch events? hard to know what's going on though without looking at it.
my code should be trying to scroll the scrollview itself, inside the swipe listener it should be telling the scrollview not to intercept touch events
scrollView.requestDisallowInterceptTouchEvent(true);
and should be implementing the scrollviews scrolling itself here:
scrollView.scrollBy(-(int)dx, -(int)dy);
maybe take a look there and see if somethings going wrong.
Ok, thanks
if you were up for it, you could probably turn the deck view into a scrollview instead by making it extend scrollview instead of framelayout.
i'm not sure what extra stuff you'd need to implement to make it work but that might be the cleanest solution for your needs
I never thought of that :)
feel free to fork my repo and improve my project :) i'm sure someone else out there will find your version useful.
or send a pull request.
Thanks
If I set a fixed height to the SwipeDeck, greater than the screen's height minus toolbar and bottom bar (there are some buttons) everything works fine. This was the problem :)
I must now find a way to get the card's height after it is drawn, then resize the deck according to the new height, or set a fixed height enough for all the content (not good, there can be a lot of information on the card).
Hi again.
So, I've taken out the main scrollview (ScrollView1) and left something like this in the main activity:
< RelativeLayout > < toolbar > < RelativeLayout > < SwipeFrameLayout > < SwipeDeck /> < /SwipeFrameLayout > < /RelativeLayout > < /RelativeLayout >
and the card layout is:
< ScrollView > < LinearLayout > content here < /LinearLayout > < /ScrollView >
I removed the scrollview variable from the SwipeListener class, and the view "v" from "onTouch" is a ScrollView, so I made some changes in the code (SwipeListener.java):
static final int MIN_DISTANCE = 110;
case MotionEvent.ACTION_DOWN: .... ((ScrollView) v).requestDisallowInterceptTouchEvent(true); // added .....
case MotionEvent.ACTION_MOVE: .... if (Math.abs(dy) > 0 && Math.abs(dx) < MIN_DISTANCE && card.getRotation() == 0) { v.scrollBy(0, -(int)dy); // added; [dx does not matter here, I guess, as the scroll is only vertical] } else { // code for card rotation }
case MotionEvent.ACTION_UP: .... ((ScrollView) v).requestDisallowInterceptTouchEvent(false); // added .....
So everyhing work kind of fine now, with a small problem: when I scroll down, it scrolls all the way to the bottom. I think "dx" value increases over time, and that's why it goes all the way down.
you might want to take all the changes from the latest branch of the project and re add the scrollview compatibility stuff i wrote. there's been a number of fixes etc since i hashed out that special version.
as for your small problem, I would just investigate what's happening there by running the code in debug mode or printing out some debug variables and just taking a look and see what's going wrong.
I took the code from the master branch.
I already followed in logcat the values for the dx/dy, and when I scroll down dy increases (-321.67932, -323.2102, -324.7312 etc)
I'm still searching for a solution; anyway, now there can be vertical scrolling and horizontal swiping, so it's pretty good :)
hey radubn and aaronbond, thanks for discussing this issue , i also want card in scrollview (only left-right swipe) , so please show me the path where is the code of this scrollview functionality.....please i really need it in my project, i used that scrollview-compat branch code but its not giving desired result
Hi. Thanks for the library, it's a good piece of work. I'd like to use it in an app with larger cards, that have a ScrollView as the main layout, so the content can scroll down if needed.
However, when I touch the card, I cannot scroll down, only swipe the card up or down. Is there a simple way to disable swiping up/down?
Thank you