Android uses the system desktop background as the application background and supports drag

Source: Internet
Author: User

In Android Application Development, if the background of the system desktop is used as the background of the application, you must set the background of the application to transparent background, and set the window attribute to flag_show_wallpaper to display the background.

Modify the activity attribute in the androidmanifest. xml file:

<Activity Android: Name = ". wallpapertest"

Android: Label = "@ string/app_name"

Android: theme = "@ Android: style/theme. translucent">

Then, add a window attribute in oncreate.

Getwindow (). addflags (windowmanager. layoutparams. flag_show_wallpaper );

When dragging the background, we mainly use the two methods of the wallpapermanager class.

Public void setwallpaperoffsetsteps
(Float xstep, float ystep) since:
API level 7

For applications that use multiple virtual screens showing a wallpaper, specify the step size between virtual screens. for example, if the launcher has 3 Virtual screens, it wocould specify an xstep of 0.5, since the x offset for those screens are 0.0, 0.5
& 1.0

Parameters
Xstep The x offset Delta from one screen to the next one
Ystep The y offset Delta from one screen to the next one

Public void setwallpaperoffsets
(Ibinder windowtoken, float xoffset, float yoffset) since:
API Level 5

Set the position of the current wallpaper within any larger space, when that wallpaper is visible behind the given window. the X and Y offsets are floating point numbers ranging from 0 to 1, representing where the wallpaper shoshould be positioned within
Screen space. These only make sense when the wallpaper is larger than the screen.

Parameters
Windowtoken The window who these offsets shoshould be associated with, as returned
View.getWindowToken()
.
Xoffset The offset along the X dimension, from 0 to 1.
Yoffset

The offset along the y dimension, from 0 to 1.

Http://blog.csdn.net/yao_guet/article/details/6572739

 

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.