我正在用Android开发一个壁纸应用程序,我正在寻找一种正确的方法来为我的应用程序设置可滚动的壁纸。现在,我的代码可以从位图中设置壁纸,但是它被裁剪成与一个页面相匹配,并且只停留在一个页面上(我在主屏幕上只有5页)。这意味着每个页面中的内容可以在壁纸中滚动,但壁纸不是滚动的。
我想设置一个可滚动的壁纸。我尝试了一些来自互联网的密码,但它们没有帮助。你们知道吗?
setImage_Wallpaper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = imageLoader.getDiscCache().get(urldisplay);
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(mContext);
try {
myWallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});我使用这段代码,但不起作用:
//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));发布于 2016-12-27 14:32:46
波斯特很老但是无论如何..。你可以试试类似的东西
public static void setWallpaper(Context context) {
int wallpaperRId = getWallpaperImageRid(context);
if (wallpaperRId == 0) {
return;
}
Bitmap tempBmp = BitmapFactory.decodeResource(context.getResources(), wallpaperRId);
// get size
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
int area = width * height / 1000;
width *= 2;
float scale = width / (float) tempBmp.getWidth();
height = (int) (scale * tempBmp.getHeight());
Bitmap bitmap = Bitmap.createScaledBitmap(tempBmp,width,height, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
wallpaperManager.setBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}https://stackoverflow.com/questions/36442175
复制相似问题