-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it work for LinearLayout#HORIZONTAL as well. #10
Comments
Hi there, thanks! I've never personally run into a use case where I needed a dynamic horizontal list; horizontal scrolling is typically reserved for ViewPager paging or gesture actions on list items. Could you elaborate on where / how you'd use this? A few thoughts regarding the implementation:
And I'm sure you were going to get around to these, but in case it's helpful:
|
Hey!
Last two:
Finally, I know this makes the code a bit messier, and I understand if you don't want to include this fork in the main project, as my UI need is maybe a bit unusual. (I do think doing this is pretty ideal for my use case, but if you know of a better way to accomplish the same thing, I'm listening). If that is the case, then thanks for the great starting point! |
So, I'm sure the fork will work for you, but if your UI consists only of a (potentially large) collection of items, DragLinearLayout may not be the ideal solution. A potentially large issue is performance - LinearLayout (and, by extension, this library) creates / inflates all its children on start. Smarter containers like the (now out-of-date) ListView and the (new hotness) RecyclerView actually recycle the Views that go off-screen and reuse them (populating them with new data so everything looks proper) with items that newly appear on-screen. If you have 10, 20 or 50 items there may be little difference. But if you have 1000 list items, lower-end devices will not be able to deal with it. Of course, even with 10 items, if you only ever see 3 on screen it is still more efficient and appropriate to use a recycling container. The recycling containers however are more complicated and handle their own scrolling - they cannot be placed alongside other children inside a ScrollView. This is the primary use case for DragLinearLayout - a relatively small number of draggable Views, inside a ScrollView container, alongside non-draggable children, with minimal hassle. Sorry if the main README does not articulate that clearly enough, I'm open to suggestions on improving the messaging. So I haven't taken the time to figure out exactly what Play Music is doing (which you could), but if I had to guess I'd wager they're using a RecyclerView with a horizontal LinearLayoutManager. This alone will give you efficient layout, scrolling and display as in Play Music. You could then use another library like DragSortAdapter to add drag support. Thankfully for you, just last week it added support for horizontal layouts. Note that I haven't had the chance to use DragSortAdapter myself, but its documentation seems reasonable. There's a guide here for an alternative custom implementation if DragSortAdapter is not working out. Using a RecyclerView may make it simpler to change your layout in the future and / or more easily adapt to different screen sizes, if you choose to do so. But if you only have a small fixed set of items, your fork of DragLinearLayout may do the job. It's your call to evaluate the trade-offs - good luck and let me know how it goes 👍 |
Hey justasm! DragSortAdapter does look like it's probably the more correct way to go about things, but honestly at this point I think I'll use my fork because it's already working. I'm not worried about performance, as I expect the case where the items go offscreen to be a pretty rare one. (common case of around 3 items) Thanks again for all of the tips! (Definitely checking out the HierarchyViewer) :D |
Reflection is Java's hammer that makes every problem a nail.. Good to hear that it worked out for you, but you're right in that it's absolutely a hack :) It is weird that there's no common interface but Android's API is hit and miss quality-wise, each View itself has some sense of the concept of scrolling, etc. Best of luck on your Android adventures! |
Actually, just thinking about it - haven't actually given this a go - you could probably just accept a View (in your case you can assume it will always be a ScrollView or HorizontalScrollView) and use its scrollBy() method instead of smoothScrollBy() to achieve similar results without needing reflection. |
Hey!
Awesome project! I'm working on this issue. It's mostly just adding a bunch of switch statements :/. Is this a thing you want? https://github.com/cmcneil/DragLinearLayout
The text was updated successfully, but these errors were encountered: