Hello everyone, today brings us a copy of the 360 Mobile phone guard Suspension window effect of the tutorial, before beginning please allow me to say a few irrelevant nonsense.
Unconsciously, I found myself in touch with Android for nearly three years, the period of all kinds of growth without the help of the master, there are always many experts like to write their own experience on the Internet for everyone to learn, I also benefited from a lot of this, I am deeply grateful. But I found that I have never put some of my usual experience to share with you, to learn together, too no dedication to the spirit. So I had a bitter experience and decided to start blogging today, hoping to guide the developers behind me and get into the Android Developer's list faster.
OK, so much for the nonsense, let's get into today's theme.
360 Mobile Guardian I believe we all know that a lot of people on the phone will install this software, then we have a desktop suspension of its effect must not be unfamiliar. Take a look at the picture below:
The first is a small suspension window shows the current use of the amount of memory, click on a small suspension window, will pop up a large suspension window, can be a key acceleration. OK, let's simulate a similar effect now.
Let's talk about the basic implementation principle, this kind of desktop suspension window effect is similar with widget, but it is more flexible than the widget. This class is mainly implemented by WindowManager, the AddView method of calling this class is used to add a suspension window, the Updateviewlayout method is used to update the parameters of the suspension window, Removeview to remove the suspension window. There is a need to specify the parameters of the suspension window.
Windowmanager.layoutparams This class is used to provide the parameters required for a suspended window, with several variables that are often used:
Type values are used to determine the types of suspension windows, typically set to 2002, above all applications, but under the status bar.
The flags value is used to determine the behavior of the suspension window, such as not focusing, modeless dialog boxes, and so on, so that you can view the document.
The gravity value is used to determine the alignment of the suspension window, generally set to the upper-left corner alignment, so that when the suspension window is dragged to facilitate the calculation of coordinates.
x value is used to determine the position of the suspension window, if you want to move the suspension window horizontally, you need to change this value.
The Y value is used to determine the position of the suspension window, and if you want to move the suspension window vertically, you need to change this value.
The width value is used to specify how wide the suspension window is.
The height value is used to specify the elevation of the suspension window.
Create a floating window the form needs to request permission from the user, so you also need to add <uses-permission android:name= to the Androidmanifest.xml android.permission.SYSTEM_ Alert_window "/>