Android to achieve QQ mobile housekeeper suspended small rocket effect

Today is the last day of 2013. First of all, I wish you a happy new year in advance! At the same time, this article is also my last article this year, so I want to make it as special as possible, with more features than usual articles. I remember that at the beginning of this year, the first article I wrote was to imitate the desktop suspended window effect of 360 mobile guard. In order to echo from beginning to end, the last article of this year will also realize the effect of desktop suspended window. Of course, the effect will be more advanced.

I believe the friends who have used QQ mobile Housekeeper will know that it has a small rocket acceleration function. Drag the small rocket to the rocket launch pad and launch, and a rocket launch animation will appear. Today, let's imitate and realize this effect.

This time, we will focus on the effect of rocket launch, so for simplicity, we will continue to develop it directly on the basis of the code that imitates the 360 mobile guard suspension window. If you haven't read that article, it is recommended to read the Android desktop suspension window effect first and imitate the 360 Mobile guard suspension window effect.

Compared with the ordinary desktop suspension window, now we need to turn the suspension window into a small rocket when dragging the suspension window, and add a rocket launch pad at the bottom of the screen. Then let's start from the rocket launch pad.

First, create launcher.xml as the layout file of the rocket launch pad

As follows:

As you can see, the ImageView here is used to display the current status of the rocket launch pad. I have prepared two pictures in advance. One is displayed when the small rocket is not dragged to the rocket launch pad, and the other is displayed when the small rocket is dragged to the rocket launch pad.

Next, create the rocketlauncher class as the view of the rocket launch pad

The code is as follows:

The code in RocketLauncher is still very simple. In the construction method, LayoutInflater's inflate () method is invoked to load the launcher.xml layout file and get the width and height of the current View. Judge in the updatelauncherstatus() method. If the parameter passed in is true, the picture of the small rocket about to launch will be displayed. If the parameter passed in is false, the picture of dragging the small rocket to the launch pad will be displayed.

Only these two files are added, and the rest is to modify the previous code. First modify the code in mywindowmanager as follows:

Mywindowmanager is the manager of all desktop suspended windows. Here, we mainly add createlauncher(), removelauncher() and updatelauncher() methods to create, remove and update the suspended windows of the rocket launch pad respectively. In addition, the isreadytolaunch () method is added to judge whether the small rocket has been dragged to the rocket launch pad. Of course, the way of judgment is also very simple. It only needs to detect the boundary of small rockets and the boundary of rocket launch pad to judge whether they intersect.

Next, you need to modify the code in floatwindowsmallview. When you drag the floating window with your finger, you need to turn it into a small rocket, as shown below:

Here, an ispressed identification bit is added to the code to determine whether the user is dragging the floating window. When dragging, call the updateviewstatus () method to update the display status of the floating window, and the floating window will become a small rocket. Then, when the finger leaves the screen, the updateviewstatus () method will also be called. If ispressed is found to be false, the floating window will be displayed again.

At the same time, when the finger leaves the screen, it will call the isreadytolaunch() method of mywindowmanager to judge whether the small rocket has been dragged to the rocket launch pad. If it is true, the animation effect of rocket launch will be triggered. The animation implementation of the rocket launch is written in the launchtask task. You can see that the time-consuming logic will be executed in the doinbackground () method to continuously reduce the ordinate of the small rocket to achieve the rising effect. When the ordinate decreases to 0, the rocket launch animation ends, and then the floating window is displayed again in the onpostexecute () method.

In addition, remember to declare two permissions in the androidmanifest.xml file, as shown below:

There is only so much code. Let's run it to see the effect. Click the start float window button on the main interface to open the float window and return to the desktop. After dragging the float window, it will become a small rocket. Drag it to the rocket launching pad at the bottom of the screen, and then let go, and the small rocket will soar up

As shown in the figure below:

Well, that's all for today's explanation. With the take-off of the small rocket, my last article of this year is over.

A new year is coming. I wish everyone in the coming year, whether working or studying, can take off like this small rocket and reach a new height! In 2014, we will continue to work together!

Please click here to download the source code

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>