Android 如何根据仿真器大小调整主屏幕壁纸

Android 如何根据仿真器大小调整主屏幕壁纸,android,android-emulator,Android,Android Emulator,嗨,我是通过编程设置主屏幕墙纸的。很好用。如何根据仿真器大小调整主屏幕壁纸。我的示例代码在这里 WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); Drawable drawable = getResources().getDrawable(R.drawable.sample); Bitmap wallpaper = ((BitmapDrawable) drawable).getBitmap();

嗨,我是通过编程设置主屏幕墙纸的。很好用。如何根据仿真器大小调整主屏幕壁纸。我的示例代码在这里

WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
Drawable drawable = getResources().getDrawable(R.drawable.sample);
Bitmap wallpaper = ((BitmapDrawable) drawable).getBitmap();           
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels;
int screenWidth = displaymetrics.widthPixels;
Bitmap bmp2 = Bitmap.createScaledBitmap(wallpaper, screenWidth, screenHeight, true);
try 
{
    wallpaperManager.setBitmap(wallpaper);
} 
catch (IOException e) 
{
    e.printStackTrace();
}

基于模拟器大小是否适合主屏幕墙纸,如何选择?
请回复您的评论,结果对我很有价值。谢谢。

也不例外。图像与主屏幕不匹配。它对我来说工作正常。这对我也很有效。但如何适应图像的宽度和高度。