Demo of freely moving floating windows in Android

Source: Internet
Author: User

Some time ago, the implementation of the android floating window was stirred up. Today, I wrote a demo of freely moving the floating window.

Brief description:

1. Move the floating window freely by overwriting the ontouchevent method in the floating view.

2. the moving of the floating window coordinates is actually the transformation of x and y in windowmananager. layoutparams, but you must set the corresponding gravity.

3. View created with windowmanager. When not needed,Be sure to rememberUse the removeview method of windowmanager to remove a scan task. Add a scan task in the activity lifecycle.

4,CodeDetailed notes are attached. For more information about the parameters, see the SDK.

Demo source code

====================================

Note the wmparams. format = 1 attribute in the demo (I used a double slash in the source code). If it is enabled, the image background will be transparent, as shown below:

 

======================================

Notes:

For some friends who haven't checked the SDK documentation for various reasons, they may not know the specific meaning of the 2002 statement in my source code such as wmparams. type = 2002, and give a statement with better readability.

As follows:

Wmparams. Type  = Layoutparams. Type_phone  ;           // Wmparams. format = pixelformat. rgba_8888; // set the image format. The effect is transparent to the background. Wmparams. Flags  = Layoutparams. Flag_not_touch_modal                                | Layoutparams. Flag_not_focusable  ;         /** the effect of the flags attribute is the same as that of "locked ". * The floating window cannot be touched. It does not accept any events and does not affect subsequent event responses. Wmparams. Flags = layoutparams. flag_not_touch_modal | layoutparams. flag_not_focusable | layoutparams. flag_not_touchable; */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.