Android壁纸不适合。 (自动溢出和作物。)

时间:2017-10-04 17:36:11

标签: android android-imageview

我的壁纸应用程序的壁纸并不适合所有设备。图像是1080x1920px,在某些设备中,壁纸会自动溢出和裁剪。

以下是我用来设置壁纸的代码;

img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                WallpaperManager wallmgr = WallpaperManager.getInstance(getApplicationContext());
                try{
                    wallmgr.setResource(+ R.drawable.a1);
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
        });

我可以做些什么来装图像?

1 个答案:

答案 0 :(得分:0)

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels; 
int width = metrics.widthPixels;
Bitmap tempbitMap = BitmapFactory.decodeResource(getResources(), R.drawable.img);
Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap,width,height, true);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); 
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
    wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
    e.printStackTrace();
}

如果我没有误会,很久以前就回答了问题?

android wallpapermanager fit screen