2014-12-07 101 views
0

我正在開發一款Android壁紙應用程序,我正在爲我的應用程序找到一個設置可滾動壁紙的正確方法。現在,我的代碼可以從位圖設置壁紙,但它被裁剪爲適合一個頁面,只停留在一個頁面上(我在主屏幕上有5個頁面)。這意味着每個頁面中的內容都可以滾動瀏覽壁紙,但壁紙不會滾動。可滾動壁紙android

我想設置一個可滾動的壁紙。我嘗試了一些來自互聯網的代碼,但他們沒有幫助。 你們有什麼想法嗎?

這是我的代碼

WallpaperManager wm = WallpaperManager.getInstance(mActivity.getContext()); 
    try { 
     wm.setBitmap(mCropImageView.getCroppedImage()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

回答

2

試試這個,它爲我工作的API> 11

//get screen height 
Display display = getWindowManager().getDefaultDisplay(); 
    Point size = new Point(); 
    display.getSize(size); 
    screenHeight = size.y; 

wallPaperBitmap= ... //your bitmap resource 

//adjust the aspect ratio of the Image 
//this is the main part 

int width = wallPaperBitmap.getWidth(); 
     width = (width * screenHeight)/wallPaperBitmap.getHeight(); 

//set the wallpaper 
//this may not be the most efficent way but it worked for me 

wallpaperManager.setBitmap(Bitmap.createScaledBitmap(wallPaperBitmap, width, height, true));