In my example, the background color changes. In the Launcher, the view turns red when over a drop target. That makes those the perfect spot to provide the user with feedback by highlighting the view or the drop target itself. Each time you leave, onDragExit is called. Each time you enter the area defined by the drop target view, onDragEnter is called. The other methods are there so the drop target knows what’s going on during the move of the object. Void onDrop (DragSource source, int x, int y, int xOffset,ĪcceptDrop is there so the drop target has a way to tell the DragController that it is willing to accept a dropped object. Void onDragExit (DragSource source, int x, int y, int xOffset, Void onDragOver (DragSource source, int x, int y, int xOffset, Void onDragEnter (DragSource source, int x, int y, int xOffset, Int yOffset,DragView dragView, Object dragInfo, Rect recycle) Rect estimateDropLocation (DragSource source, int x, int y, int xOffset, Int yOffset,DragView dragView, Object dragInfo) The DropTarget interface defines the following methods: boolean acceptDrop (DragSource source, int x, int y, int xOffset, In code, what’s going on is that the Trash view implements the DropTarget interface. Since it is a trash icon, you know that it means the icon being dragged will be removed from the workspace. The red color gives you a good indication that something will happen if you drop the icon there. If you drag an icon over that icon, you will see a change in the color of the view being dragged. You should see that a Trash icon appears. In the Launcher, when you start dragging an icon, check out what happens at the bottom of the screen. Here’s how DropTargets figure into the Android Launcher. The one object I did not explore fully was the DropTarget. The Launcher object model includes objects like DragLayer, DragSource, DragController, and DropTarget. In an earlier note (see “ Moving Views In Android – Part 2“), I had written up how the Android Launcher app supports moveable views using the touch interface. The classes in this app are derived from the Android Launcher application. The other two show the background color changes in the drop zones as you move over them. Figure 2 shows the menu where you can add other objects and enable and disable the orange drop zone. There are two red drop zones and one orange drop zone. ![]() Figure 1 is what it looks like when it launches. ![]() The figures show what the app looks like at various points. As you drag views around the screen, the drop zones light up to indicate that they are places where you can drop objects. In my example, I called those areas DropZones. I also worked out how you can have different drop behavior for different areas of the screen. ![]() I now understand how views can be placed on the screen and moved by touching them. I have come to the end of my work on drag-drop in Android.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |