画面サイズに一致する画像でホーム画面に壁紙を適用するアプリがあります。これは壁紙を設定するための私のコードです:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeResource(getResources(), wallpapersPagerAdapter.getWallpaperId(position), options);
wallpaperManager.suggestDesiredDimensions(options.outWidth, options.outHeight);
wallpaperManager.setResource(wallpapersPagerAdapter.getWallpaperId(position));
} catch (IOException e) {
Log.e(Constants.LOG_TAG, e.getMessage());
Toast.makeText(MainActivity.this, R.string.err_can_not_set_wallpaper, Toast.LENGTH_SHORT).show();
return;
}
また、ほとんどのデバイスで完全に機能しましたが、Galaxy suggestDesiredDimensions()
s4 と Galaxy s3 にはまったく影響しません (他のサムスンの携帯電話にも同じ問題があると思います)。この電話では、目的の寸法に関係なく、画像がスケーリングされます。
Backgrounds HD
しかし、アプリケーションにはこの問題がないことがわかりました。私の壁紙の実際のサイズが1080x1920であると仮定して、どうすればgalaxy s4(またはs3)に壁紙をトリミングせずに設定できるのだろうか?