壁纸只放大我的手机

时间:2017-10-12 06:04:10

标签: android zoom zooming android-wallpaper

我试图创建一个从drawable中选择图像并将其设置为壁纸的应用程序。它与其他手机如Galaxy和Infinix配合使用,但当我在自己的华为手机上设置时,壁纸会放大。

   public void setWallpaper(View view) throws IOException {

    Bitmap bmp1=((BitmapDrawable)imageView.getDrawable()).getBitmap();
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int height = displaymetrics.heightPixels;
    int width = displaymetrics.widthPixels;
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
    Bitmap bmp2 = Bitmap.createScaledBitmap(bmp1, width, height, true);
    wallpaperManager.suggestDesiredDimensions(width, height);
    wallpaperManager.setWallpaperOffsetSteps(1, 1);
    try {
        wallpaperManager.setBitmap(bmp2);
        Toast.makeText(getApplicationContext(),"Wallpaper set",Toast.LENGTH_LONG).show();
        progress.setVisibility(View.INVISIBLE);
   }
   catch (IOException e) {
       e.printStackTrace();
   }

0 个答案:

没有答案