墙纸不正确地放在设备屏幕上,它可以变焦或裁剪

发布于 2025-02-02 14:05:43 字数 2023 浏览 4 评论 0原文

我使用链接图像创建了带有滑行的壁纸应用程序。我有三个按钮可以将图像设置为墙纸,锁定屏幕和home_screen在设备屏幕上。但是,当我将此图像设置为墙纸时,它要么缩放或裁剪。我希望图像适合每个Android屏幕尺寸。

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.button2:            

            Bitmap bitmap1 = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            WallpaperManager manager1 = WallpaperManager.getInstance(getApplicationContext());
            try {
                manager1.setBitmap(bitmap1, null, false, WallpaperManager.FLAG_SYSTEM);
                Toast.makeText(getApplicationContext(), "Set HomeScreen Successfully ", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.button3:              

            Bitmap bitmap2 = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            WallpaperManager manager2 = WallpaperManager.getInstance(getApplicationContext());
            try {
                manager2.setBitmap(bitmap2, null, false, WallpaperManager.FLAG_LOCK);
                Toast.makeText(getApplicationContext(), "Set LockScreen Successfully ", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.button4:               

            Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
            try {
                manager.setBitmap(bitmap);
                Toast.makeText(getApplicationContext(), "Set Wallpaper Successfully ", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT).show();
            }

    }
}

}

I created wallpaper app with glide using link images. I have three buttons to set image as wallpaper, lock-Screen and Home_Screen on device screen. But when I set this image as wallpaper its either zoom or cropped. I want image should fit on every android screen size.

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.button2:            

            Bitmap bitmap1 = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            WallpaperManager manager1 = WallpaperManager.getInstance(getApplicationContext());
            try {
                manager1.setBitmap(bitmap1, null, false, WallpaperManager.FLAG_SYSTEM);
                Toast.makeText(getApplicationContext(), "Set HomeScreen Successfully ", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.button3:              

            Bitmap bitmap2 = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            WallpaperManager manager2 = WallpaperManager.getInstance(getApplicationContext());
            try {
                manager2.setBitmap(bitmap2, null, false, WallpaperManager.FLAG_LOCK);
                Toast.makeText(getApplicationContext(), "Set LockScreen Successfully ", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.button4:               

            Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
            try {
                manager.setBitmap(bitmap);
                Toast.makeText(getApplicationContext(), "Set Wallpaper Successfully ", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                Toast.makeText(this, "Wallpaper not load yet!", Toast.LENGTH_SHORT).show();
            }

    }
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文