壁纸未缩放到设备的显示屏

时间:2018-01-31 19:04:47

标签: java android android-wallpaper

我想通过点击按钮将图像设置为设备的壁纸

我设置了点击监听器( setWall ),但图片未缩放到设备的显示器。

imageBrought = getIntent().getExtras().getString("appMomentImage");         
Glide.with(getApplicationContext()).load(imageBrought).dontAnimate().into(imagePreview);

    setWall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           Glide.with(getApplicationContext()).load(imageBrought).asBitmap().into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {

                    try {

                       WallpaperManager.getInstance(getApplicationContext()).setBitmap(resource);


                    } catch (IOException e) {

                        e.printStackTrace();

                    }

                    Toast.makeText(getApplicationContext(), "Your Wallpaper Has Been Set!", Toast.LENGTH_LONG).show();

                }
            });
        }
    });

1 个答案:

答案 0 :(得分:1)

您可以使用此设备获取设备指标,然后只传递给您的图片

DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    metrics.heightPixels;
    metrics.widthPixels;