I created a drag and drop gridview (using an OnDragListener). Grid items can be dropped upon one another. However, I also want to be able to re-order them. I implemented this, but there is a major issue left standing: the user control part.
When I drag around my shadow object I want the items to make space for my dragged object while I am dragging it around. I already implemented the moving of the other items, but I cannot seem to figure out a way to find out IF/WHEN I am in between two items. I get drag events when I hoover ABOVE an item, but not in between then. The gridview does not get any onTouchEvent calls when I am dragging, not even onInterceptTouchEvent calls.
Does anyone know a way in which I can implement this?
I already tried:
Implementing onTouchEvent and onInterceptTouchEvent in the gridview. Problem:
The gridview does not get any onTouchEvent calls when I am dragging an item, not even onInterceptTouchEvent calls.
Setting another draglistener on the whole gridview. Problem: ACTION_DRAG_LOCATION gets only called a few times, not on every move (location change), as is documented (!!).
I removed the padding between the grid items and gave the items themselfes some extra size, so that you are never inbetween items, but also on the side of one of the items. I detect when I'm at the side of an item and move the items accordingly to make space for my dragged item.
Related
I am creating a custom scroll inside RecyclerView and I did most of the work already but now I came to hopefully one of the last problems.
On scrolling, I am expanding/collapsing rows as they move up or down. It works fine until I reach the bottom of the list. Two items remain in their normal state because I can no longer scroll down and therefore they will not expand.
My question is, how can I scroll under the recyclerView when I reach the bottom? Do I need to implement onTouch listener and do the work from there? Or is there something in RecyclerView that can help me create the underscroll?
You should be able to expand them in onOverScrolled, as that will be called at the correct time to trigger their expansion.
I need a component that works like the picture below but I'm having trouble coming up with some kind of decent solution that works.
I want the list to have a center locked selection but being scrollable with the d-pad. This is for an application running on a TV so no need for touch scroll. So when pressing down on the remote d-pad the list will scroll and a new item will size up and the current selected one will size down and the new selection will still be in the middle.
I've tried doing this using a ListView that I extended and programmatically scrolling when pressing down or up. On scroll finished I called notifyDatasetChanged() on the ListView for re-inflating of the childs and in the ListViews adapters getView() I made the animation of the view located at the current selected position.
This is not optimal since I need to call notifyDatasetChanged(), which re-inflates all visible views, for the animation to apply. The UI becomes laggy when doing this and scrolling fast. It's also not possible to make som kind of compress animation when current selected item goes out of selection. There is also some trouble with the end items (read views) such the first or last in the list when doing animation of them, the may sometimes go out of screen.
I think that his must have been done before and maybe I'm missing it when searching for an answer.
Have anyone done something similar or do you have some suggestions of how this can be achieved? Maybe I'm just starting of with the wrong component here..
Regards,
Kristoffer
I need to do some animations in a listview after it is flinged and is about to stop.I have a listview which is going to be of a fixed height(well dont ask me why), and whenever the scroll stops , it should have three elements visible. What i do now is detect when the list reaches SCROLL_STATE_IDLE and if i have two elements visible at that time, i use smoothScrollToPosition and reach a state of 3 items visible and it works fine, but what i would like to do is detect when the scroll is about to stop and stop the scroll programatically when there are three items visible. Is that even possible... Any code snippets, pseudo code, algo would help me.
You can set an OnScrollListener, and then store the value from absListView.getScrollY() each sample and compare it the previous sample to compute the velocity of the scroll. Once that drops below a threshold you define, you can take over scrolling.
I want an expandable list in which I can drag a child item and drop it over some other parent list item which will result in child moving from one parent to other. I only need a direction how we can achieve this in general listview (let alone exapandable). Examples are available for picking up a listitem to change the order of listview i.e. to sort that list. How can I accomplish dropping over a view in order to group them.
Your best bet will be putting your effort on customizing and making your own listview, Consider extending AdapterView, this will give you more power over controlling child display and organizations, Putting animation such and drag and drop will be easier for you in this case, Otherwise with simple list view it might work but i doubt if it would generate the required result you want.
Here is a link for exending AdapterView and customizations, go through it it will give you enough confidance to put in your animation. I tried almost similar stuff and was succesfull by same way, unfortunately I dont have implemented code with me.
http://developer.sonymobile.com/2010/05/20/android-tutorial-making-your-own-3d-list-part-1/
Else with list view try doing following,
Your listview should be wrapped inside a framelayout, you will need layers
Enable drawing cache for childrens, coz animation you seek requires playing with bitmaps
Second, when you touch a child in listview, get the bitmap of child, and inflate it at same coordinates of touched child, you can get position of Child easily.
Now time for some animation, you enable drag and drop over inflated bitmap, now when you move it, first thing you need to do is, shifting all the childrens in list view either Up or Down depending upon movement of finger, you can define somekind of threshold like unless half the height of children is moved you wont shift childs in listview up or down.
Moving child will be easy, all you need to do is applying Transformation animation to all the currently visible child in listview, use childCount and ChildAt api for the same, and animation set for playing them together.
Thats it when you build space by shifting child, user will feel like drag drop and shift, all the thing you need, when user places it a place, just modify your dataset underneath listview reposition it based on recent changes by user and refresh it,so that listview reorders itself.
In my application I have a custom gallery which shows some LinearLayouts (custom components to be precise, but that doesn't matter I think).
What I want is that if I scroll in between to items that it stays there and doesn't select the closest one (as it does by default).
If I override the onTouchEvent and in the case of an ACTION_UP ignore the event I get the desired result, BUT then I lose the onFling (the scrolling doesn't continue but stops immediately).
Then I think I'll have problems with my indicator of the position as I will probably lose the OnItemSelected handle, but I'm not sure of that (of course).
every suggestion is welcome.