A control dragging method, device and storage medium based on an Android system
By creating a parent layout and parent container in the Android system, and using coordinate system acquisition and long press listener, various drag effects of parent and child controls are implemented, solving the problem that existing technologies cannot meet complex usage scenarios and simplifying user operations.
Patent Information
- Application Number
- CN202211513603.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-29
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2042-11-29
AI Technical Summary
The existing Android system's control dragging methods cannot achieve various dragging effects between parent and child controls, and cannot meet the needs of complex use cases.
By adding a parent layout to the root layout of the view, multiple parent containers are created, and a planar coordinate system is established in the display area of the root layout to obtain the coordinates of each parent container. This enables dragging operations of parent containers and child items, including long-press listening and coordinate comparison to change their positions.
It implements various drag effects for the parent container and its child controls, meeting the drag needs in complex scenarios and simplifying user operations.
Smart Images

Figure CN115729432B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer control, more particularly, to a control dragging method based on an Android system, a device and a storage medium. BACKGROUND
[0002] The current Android system commonly used dragging control can only drag the controls in the same layer, and the function is relatively single. For the parent control containing sub-controls, it is necessary to realize the complex use scene of multiple dragging results, for example: 1. Dragging the parent control to change the order of all parent controls; 2. Dragging the sub-control to move within the parent control to change the order of all sub-controls in the parent control; 3. Dragging the sub-control out of the current parent control and adding it to other parent controls. For the above needs, the current dragging control cannot realize it. SUMMARY
[0003] In view of at least one defect or improvement demand of the prior art, the present application provides a control dragging method based on an Android system, a device and a storage medium, which realizes multiple dragging effects of parent containers and their sub-controls, meets the dragging needs in complex scenes, and simplifies user operation.
[0004] To achieve the above-mentioned purpose, according to the first aspect of the present application, a control dragging method based on an Android system is provided, which comprises:
[0005] adding a parent layout in the root layout of a view, and creating a plurality of parent containers in the parent layout;
[0006] selecting a first parent container from the plurality of parent containers;
[0007] establishing a plane coordinate system in the display area of the root layout, and respectively acquiring a first coordinate of the first parent container and a second coordinate of a second parent container to be exchanged;
[0008] deleting the first parent container from the parent layout, and adding the first parent container to the original coordinate position of the second parent container according to the first coordinate of the first parent container and the second coordinate of the second parent container, and moving the parent layout to the display area where the first parent container is currently located.
[0009] Further, the above-mentioned control dragging method based on an Android system, wherein the plurality of parent containers in the parent layout are arranged in a horizontal direction, and the plurality of parent containers are in the same display area under the same view, or the plurality of parent containers are in different display areas under the same view.
[0010] Further, the above-mentioned control dragging method based on an Android system, wherein each parent container comprises a head, a tail and a plurality of sub-items, and the plurality of sub-items are arranged in a vertical direction.
[0011] Further, the control dragging method based on the Android system, wherein the method further comprises:
[0012] respectively setting long press listening for the head, the tail and the plurality of sub-items in the first parent container;
[0013] dragging the whole parent container to change the position of the parent container in the parent layout when receiving the long press listening signal of the head of the first parent container and / or the tail of the parent container;
[0014] dragging the first sub-item in the first parent container to change the position of the sub-item in the first parent container when receiving the first listening signal of the first sub-item.
[0015] Further, the control dragging method based on the Android system, wherein the dragging the first sub-item in the first parent container to change the position of the sub-item in the first parent container when receiving the first listening signal of the first sub-item specifically comprises:
[0016] obtaining a third coordinate of the first sub-item and a fourth coordinate of a second sub-item to be exchanged;
[0017] deleting the first sub-item from the first parent container and adding the first sub-item to the coordinate position of the second sub-item to change the position of the sub-item in the first parent container according to the third coordinate of the first sub-item and the fourth coordinate of the second sub-item.
[0018] Further, the control dragging method based on the Android system, wherein the method further comprises:
[0019] respectively setting long press listening for the head, the tail and the plurality of sub-items in the first parent container;
[0020] dragging the third sub-item in the first parent container to change the parent container to which the sub-item belongs when receiving the second listening signal of the third sub-item.
[0021] Further, the control dragging method based on the Android system, wherein the dragging the third sub-item in the first parent container to change the parent container to which the sub-item belongs when receiving the second listening signal of the third sub-item specifically comprises:
[0022] obtaining a fifth coordinate of the third sub-item;
[0023] The fifth coordinate of the third sub-entry is deleted from the first parent container, and the third sub-entry is added to any position in the second parent container according to the fifth coordinate of the third sub-entry and the second coordinate of the second parent container to be added.
[0024] Furthermore, in the above-mentioned control dragging method based on the Android system, when dragging the parent container or the child item, the icon corresponding to the selected parent container or child item is set to invisible, and after the dragging operation is completed, the icon corresponding to the selected parent container or child item is set to visible.
[0025] According to a second aspect of the present invention, a control dragging device based on the Android system is also provided, which includes at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program, and when the computer program is executed by the processing unit, the processing unit performs the steps of any of the methods described above.
[0026] According to a third aspect of the invention, a storage medium is also provided, which stores a computer program executable by an Android-based control dragging device, which, when the computer program is run on the Android-based control dragging device, causes the access authentication device to perform the steps of any of the methods described above.
[0027] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects:
[0028] The Android-based control dragging method provided by this invention can drag the parent container, drag the child item, and drag the child item away from the current parent container and add it to other parent containers by deleting the first parent container / first child item from its parent layout / parent container and adding it to the second parent container. This achieves various dragging effects of the parent container and its child controls, meets the dragging needs in complex scenarios, and simplifies user operation. Attached Figure Description
[0029] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0030] Figure 1 A flowchart illustrating a control dragging method based on the Android system provided in this application embodiment;
[0031] Figure 2 This is a flowchart illustrating a control dragging method based on the Android system, as provided in an embodiment of this application. Detailed Implementation
[0032] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0033] The terms "first," "second," "third," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0034] This application provides a control dragging method based on the Android system. Figure 1 This is a flowchart illustrating a control dragging method based on the Android system, provided in an embodiment of this application. Figure 2 This is a flowchart illustrating a control dragging method based on the Android system, provided as an embodiment of this application. Please refer to [link / reference]. Figure 1 and Figure 2 The method includes:
[0035] (1) Add a parent layout to the root layout of the view, and create several parent containers in the parent layout;
[0036] Specifically, the root layout mRootLayout inherits from the horizontal scroll view HorizontalScrollView. The parent layout mParentLayout is added to the root layout through the addView() operation. The parent layout mParentLayout is a horizontal linear layout LinearLayout.
[0037] (2) Select the first parent container from among several parent containers;
[0038] Each parent container mParentContain includes a headView, a footView, and several child items mChildView. Multiple child items mChildView are added to the parent container mParentContain using the addView() operation, and these child items are arranged vertically.
[0039] Set long-press listeners for the header, footer, and several child items in the first parent container;
[0040] When a long press listen signal is received at the head and / or tail of the first parent container, drag the entire parent container to change its position in the parent layout.
[0041] (3) Establish a planar coordinate system in the display area of the root layout, and obtain the first coordinates of the first parent container and the second coordinates of the second parent container to be swapped respectively;
[0042] In this context, the parent containers mParentContain within the parent layout mParentLayout are arranged horizontally, and these parent containers may be in the same display area under the same view, or in different display areas under the same view.
[0043] The second parent container is one of the left and right parent containers of the first parent container, either `leftContain` or `rightContain`. In other words, the second parent container can be any parent container in the parent layout other than the first parent container. If the second parent container is not empty, the coordinates of `leftContain` and `rightContain` within their respective display areas are obtained using `view.getLocationOnScreen(location)`.
[0044] (4) Delete the first parent container from the parent layout, and add the first parent container to the original coordinate position of the second parent container according to the first coordinate of the first parent container and the second coordinate of the second parent container, and move the parent layout to the display area where the first parent container is currently located.
[0045] Specifically, the x-coordinate of the drag operation is compared with the x-coordinates of `leftContain` and `rightContain` respectively to determine whether to swap positions with `leftContain` or `rightContain`. If so, the first parent container is first removed from the parent layout `mParentLayout` and then added to the right of `rightContain` to move it to the right; or it is added to the left of `leftContain` to move it to the left. Simultaneously, `mRootLayout.scrollTo(newX,0)` is called to scroll the parent layout to the current position, achieving a horizontal scrolling effect.
[0046] Specifically, when a long press triggers a drag operation `MotionEvent.ACTION_DOWN`, the corresponding parent container icon `BitmapDrawable` is obtained based on the first parent container being dragged. The icon corresponding to the selected parent container is set to invisible, and after the drag operation ends, the icon corresponding to the selected parent container is made visible again. During the drag process, i.e., the `MotionEvent.ACTION_MOVE` event, the horizontal and vertical coordinates of the drag operation are continuously obtained through the `event.getX()` and `event.getY()` functions. The display position of the drag icon `dragView` is updated through `drawable.setBounds(rect)`, and `invalidate()` is called to refresh the interface, thus achieving the effect of the icon following the finger or mouse movement.
[0047] In one specific embodiment, long-press listeners are set for the head, tail, and several child items in the first parent container, respectively;
[0048] When the first listener signal is received for the first child entry in the first parent container, drag the first child entry to change its position in the first parent container.
[0049] Specifically, obtain the third coordinate of the first sub-entry and the fourth coordinate of the second sub-entry to be swapped;
[0050] The first sub-entry is deleted from the first parent container, and the first sub-entry is added to the original coordinate position of the second sub-entry based on the third coordinate of the first sub-entry and the fourth coordinate of the second sub-entry, thereby changing the position of the sub-entry and all sub-entries in the first parent container.
[0051] Specifically, the second sub-item is either the sub-item above the first sub-item (aboveView) or the sub-item below the first sub-item; that is, the second sub-item can be any sub-item in the first parent container other than the first sub-item. If the second sub-item is not empty, the coordinates of aboveView and belowView in their respective display areas are obtained by view.getLocationOnScreen(location).
[0052] The vertical coordinate of the drag operation is compared with the vertical coordinates of aboveView and belowView respectively to determine whether to swap positions with aboveView or belowView. If so, the first child item mChildView is first deleted from the first parent container and then added to aboveView to move it upward, or added to belowView to move it downward.
[0053] Specifically, when a long press triggers a drag operation `MotionEvent.ACTION_DOWN`, the corresponding sub-item icon `BitmapDrawable` is obtained based on the currently dragged sub-item. The icon corresponding to the first selected sub-item is set to invisible. The drag operation ends at `MotionEvent.ACTION_UP`, the dragView icon that follows the finger movement is set to null, and the first selected sub-item is made visible.
[0054] In one specific embodiment, long-press listeners are set for the head, tail, and several child items in the first parent container, respectively;
[0055] When a second listener signal is received for the third child entry in the first parent container, drag the third child entry to change the parent container to which the child entry belongs.
[0056] Specifically, obtain the fifth coordinate of the third sub-entry;
[0057] Remove the fifth coordinate of the third child entry from the first parent container, and add the third child entry to any position in the second parent container based on the fifth coordinate of the third child entry and the second coordinate of the second parent container to be added.
[0058] Specifically, the second parent container is one of the left and right parent containers of the first parent container, namely `leftContain` and `rightContain`. That is, the second parent container can be any parent container in the parent layout other than the first parent container. If the second parent container is not empty, the coordinates of `leftContain` and `rightContain` in their respective display areas are obtained by `view.getLocationOnScreen(location)`.
[0059] The x-coordinate of the drag operation is compared with the x-coordinates of both `leftContainer` and `rightContainer` to determine whether the parent container of the third child view `mChildView` needs to be changed. If so, the third child view `mChildView` is first removed from the first parent container, then added to either `leftContainer` or `rightContainer`. The position of the third child view within the second parent container is determined based on the y-coordinate of the drag operation. Simultaneously, `mRootLayout.scrollTo(newX,0)` is called to scroll the parent layout to the current position, achieving a horizontal scrolling effect.
[0060] Specifically, when a long press triggers a drag operation `MotionEvent.ACTION_DOWN`, the corresponding sub-item icon `BitmapDrawable` is obtained based on the currently dragged sub-item. The icon corresponding to the selected third sub-item is made invisible. The drag operation ends at `MotionEvent.ACTION_UP`, the dragView icon that follows the finger movement is set to null, and the dragged third sub-item is made visible.
[0061] This application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method. The computer-readable storage medium may include, but is not limited to, any type of disk, including floppy disks, optical disks, DVDs, CD-ROMs, microdrives, as well as magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic cards or optical cards, nanosystems (including molecular memory ICs), or any type of medium or device suitable for storing instructions and / or data.
[0062] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0063] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0064] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between devices or units may be electrical or other forms.
[0065] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0066] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0067] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0068] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0069] The foregoing description is merely an exemplary embodiment of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Those skilled in the art will readily conceive of embodiments of this disclosure upon considering the specification and practicing the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described herein. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.
[0070] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0071] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A control dragging method based on an Android system, characterized in that, The method comprises the following steps: adding a parent layout in the root layout of a view, and creating several parent containers in the parent layout; selecting a first parent container from the several parent containers; setting long press listening for the head, tail and several sub-entries in the first parent container, respectively; when receiving the long press listening signal of the head and / or tail of the first parent container, dragging the whole parent container to change the position of the parent container in the parent layout; establishing a plane coordinate system in the display area of the root layout, and obtaining the first coordinate of the first parent container and the second coordinate of a second parent container to be exchanged, respectively; comparing the horizontal coordinate of the dragging operation with the horizontal coordinate of the second parent container on the left and right sides of the first parent container, and judging whether to exchange the position with the second parent container; deleting the first parent container from the parent layout, and adding the first parent container to the coordinate position of the second parent container according to the first coordinate of the first parent container and the second coordinate of the second parent container, and moving the parent layout to the display area where the first parent container is currently located. 2.The Android system-based control dragging method of claim 1, wherein, The several parent containers in the parent layout are arranged in a horizontal direction, and the several parent containers are in the same display area under the same view, or the several parent containers are in different display areas under the same view. 3.The Android system-based control dragging method of claim 1, wherein, Each parent container comprises a head, a tail and several sub-entries, and the several sub-entries are arranged in a vertical direction. 4.The Android system-based control dragging method of claim 3, wherein, The method further comprises the following steps: when receiving the first listening signal of a first sub-entry in the first parent container, dragging the first sub-entry to change the position of the sub-entry in the first parent container. 5.The Android system-based control dragging method of claim 4, wherein, The step of dragging the first sub-entry to change the position of the sub-entry in the first parent container when receiving the first listening signal of the first sub-entry in the first parent container specifically comprises the following steps: obtaining the third coordinate of the first sub-entry and the fourth coordinate of a second sub-entry to be exchanged; deleting the first sub-entry from the first parent container, and adding the first sub-entry to the coordinate position of the second sub-entry according to the third coordinate of the first sub-entry and the fourth coordinate of the second sub-entry, so as to change the position of the sub-entry in the first parent container. 6.The Android system-based control dragging method of claim 3, wherein, The method further comprises the following steps: when receiving the second listening signal of a third sub-entry in the first parent container, dragging the third sub-entry to change the parent container to which the sub-entry belongs. 7.The Android system-based control dragging method of claim 6, wherein, The step of dragging the third sub-entry to change the parent container in which the sub-entry is located when receiving the second listening signal of the third sub-entry in the first parent container specifically comprises the following steps: obtaining the fifth coordinate of the third sub-entry; deleting the fifth coordinate of the third sub-entry from the first parent container, and adding the third sub-entry to any position in a second parent container to be added according to the fifth coordinate of the third sub-entry and the second coordinate of the second parent container. 8.The Android system-based control dragging method of claim 4 or 6, wherein, When the parent container or the sub-entry is dragged, the icon corresponding to the selected parent container or sub-entry is set to be invisible, and after the dragging operation is completed, the icon corresponding to the selected parent container or sub-entry is set to be visible.
9. An Android system-based control dragging device, characterized in that, The application also discloses a control-dragging method device of an Android system, which comprises at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program which, when executed by the processing unit, enables the processing unit to execute the steps of the method according to any one of claims 1-8.
10. A storage medium, characterized by The application also discloses a control-dragging method device of an Android system, which comprises at least one processing unit and at least one storage unit, wherein the storage unit stores a computer program which, when executed by the processing unit, enables the processing unit to execute the steps of the method according to any one of claims 1-8.
Citation Information
Patent Citations
Dragging-moving method of files under same directory for Android system
CN106020657A
Control-based loading display method and related device
CN113360211A