Platforma przeciągania i upuszczania na Androidzie umożliwia dodawanie do aplikacji funkcji przeciągania i upuszczania. Dzięki niej użytkownicy mogą kopiować i przenosić tekst, obrazy, obiekty i inne treści, które mogą być reprezentowane przez identyfikator URI, z View do drugiego w aplikacji lub między aplikacjami w trybie wielu okien.
Rysunek 1. Przeciągnij i upuść element w aplikacji.
Rysunek 2. Przeciągaj i upuszczaj aplikacje.
Platforma zawiera klasę zdarzeń przeciągania, detektory zdarzeń przeciągania oraz klasy pomocnicze. Platforma ma służyć przede wszystkim do przenoszenia danych, ale można jej używać też do innych działań w interfejsie. Na przykład możesz utworzyć aplikację, która łączy kolory,
gdy użytkownik przeciąga ikonę koloru na inną ikonę. W pozostałej części dokumentu opisujemy, jak działa metoda „przeciągnij i upuść” w kontekście przenoszenia danych.
Przegląd
Proces przeciągania obejmuje kilka elementów.
Przeciąganie źródła: widok punktu początkowego procesu przeciągania i upuszczania.
Element docelowy: widok, w którym można akceptować dane przeciągania.
Przeciągany cień:cień do przeciągania reprezentuje przeciągane dane i jest widoczny dla użytkowników.
Zdarzenia przeciągania: gdy użytkownik przesuwa cień nad układem aplikacji, system wysyła zdarzenia przeciągania do detektorów zdarzeń przeciągania i metod wywołania zwrotnego powiązanych z obiektami View w układzie.
Operacja przeciągania i upuszczania rozpoczyna się, gdy użytkownik wykonuje gest interfejsu rozpoznawany przez aplikację jako sygnał do rozpoczęcia przeciągania danych. W odpowiedzi aplikacja powiadamia system, że rozpoczyna się operacja przeciągania i upuszczania. System wywołuje Twoją aplikację, aby uzyskać cień do przeciągania i pokazać go użytkownikom podczas przeciągania i upuszczania.
Gdy użytkownik przesuwa cień nad układem aplikacji, system wysyła zdarzenia przeciągania do detektorów zdarzeń przeciągania i metod wywołania zwrotnego powiązanych z obiektami View w układzie. Jeśli użytkownik zwolni cień na obszar docelowy, system wyśle do niego dane. Przeciąganie i upuszczanie kończy się, gdy użytkownik zwolni cień, niezależnie od tego, czy cień znajdzie się nad elementem docelowym.
Przeciągnij i upuść Sample zawierającą różne sposoby przeciągania i upuszczania oraz obsługi multimediów.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-26 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-07-26 UTC."],[],[],null,["# Enable drag and drop\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to use drag and drop in Compose. \n[Drag and drop →](/develop/ui/compose/touch-input/user-interactions/drag-and-drop) \n\n\u003cbr /\u003e\n\n| **Note:** See the improved method of implementing drag and drop in [Receive rich\n| content](/develop/ui/views/receive-rich-content) for a better UX and improved maintainability of your code.\n\nThe Android drag-and-drop framework lets you add interactive drag-and-drop\ncapabilities to your app. With drag and drop, users can copy or move text,\nimages, objects, and any content that can be represented by a URI, from one\n[`View`](/reference/android/view/View) to another within an app, or between apps\nin [multi-window mode](/develop/ui/views/touch-and-input/drag-drop/multi-window#DragPermissionsMultiWindow).\n\n|--------------------------------------------|-------------------------------------------|\n| | |\n| **Figure 1.** Drag and drop within an app. | **Figure 2.** Drag and drop between apps. |\n\nThe framework includes a drag event class, drag listeners, and helper classes\nand methods. Although primarily designed to enable the transfer of data, you can\nuse the framework for other UI actions. For example, you can create an app that\nmixes colors when the user drags a color icon over another icon. However, the\nrest of document describes the drag-and-drop framework in the context of data\ntransfer.\n\nOverview\n--------\n\nThere are a few elements involved in the drag process.\n\n1. Drag source: The start point view of drag-and-drop process.\n\n2. Drop target: A view that can accept the drag data.\n\n3. [Drag shadow](/develop/ui/views/touch-and-input/drag-drop/concepts#AboutDragShadowBuilder):\n A *drag shadow* is a representation\n of the data being dragged, it's visible to users.\n\n4. [Drag events](/develop/ui/views/touch-and-input/drag-drop/concepts#AboutDragEvent):\n As the user moves the drag shadow over the\n app's layout, the system sends drag events to the drag event listeners and\n callback methods associated with the `View` objects in the layout.\n\nA drag-and-drop operation starts when the user makes a UI gesture that your app\nrecognizes as a signal to start dragging data. In\nresponse, the app notifies the system that a drag-and-drop operation is\nstarting. The system calls back to your\napp to get a *drag shadow*. and show it to users during drag-and-drop process.\n\nAs the user moves the drag shadow over the app's layout, the system sends drag\nevents to the [drag event listeners and callback methods](/develop/ui/views/touch-and-input/drag-drop/concepts#AboutDragListeners)\nassociated with the `View` objects in the layout. If the user releases the drag\nshadow over a drop target, the system sends the data to it. The drag-and-drop\noperation ends when the user releases the drag shadow, whether or not the drag\nshadow is over a drop target.\n\nTopics\n------\n\n[Key Concepts](/develop/ui/views/touch-and-input/drag-drop/concepts)\n: Understand the drag-and-drop process.\n\n[DropHelper for simplified drag and drop](/develop/ui/views/touch-and-input/drag-drop/drophelper)\n: Learn how to implement drag and drop with `DropHelper`.\n\n[Implement drag and drop with views](/develop/ui/views/touch-and-input/drag-drop/view)\n: Alternatively, implement drag and drop with Android views, this allows\n developers to have more control of the details.\n\n[Drag and drop in multi-window mode](/develop/ui/views/touch-and-input/drag-drop/multi-window)\n: Support drag and drop in multi-window mode, allow objects to move across\n different applications.\n\nAdditional resources\n--------------------\n\n- [Codelab for Drag and Drop](/codelabs/codelab-dnd-views) using views\n- [Drag \\& drop for seamless multitasking](https://www.youtube.com/watch?v=WOm76wSfkbU) video\n- [Drag and Drop Samples](https://github.com/android/platform-samples/tree/main/samples/user-interface/draganddrop) which contains various ways to implement drag and drop along with accepting rich media."]]