我做了一个应用程序,它在定时的时间间隔使用几个 png 图像设置壁纸。屏幕上显示的壁纸尺寸并非所有设备都正确。在 9.7 英寸的平板电脑上,尺寸非常完美,其中包含足够的空间来左右滚动。但在手机上,每张图像只能看到一小部分。看起来像是放大了。
我需要什么编码来告诉 Android 在所有设备上以正确的大小显示图像?
我假设 WallpaperManager 做到了这一点,但似乎我还不知道如何使用它。
以下是我更改墙纸的方法:
myWallpaperManager.setResource(R.drawable.muzdalifah);
编辑显示用于更改壁纸的所有代码:
public class AlarmReceiverChangeImage extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
/*
* Make the settings available from the settings xml file.
*/
SharedPreferences mySettings = PreferenceManager
.getDefaultSharedPreferences(context);
/*
* Allow editing.
*/
SharedPreferences.Editor editor = mySettings.edit();
/*
* Get the settings into variables.
*/
boolean bln_checkbox_changing_is_activated = mySettings.getBoolean(
"checkbox_changing_is_activated", false);
String myCurrentImageName = mySettings.getString("current_image",
"kabanight1");
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(context.getApplicationContext());
if (bln_checkbox_changing_is_activated == true) {
if (myCurrentImageName.equals("tentcity")) {
try {
myWallpaperManager.setResource(R.drawable.kabacloseup);
myCurrentImageName = "kabacloseup";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("kabacloseup")) {
try {
myWallpaperManager.setResource(R.drawable.kabanight1);
myCurrentImageName = "kabanight1";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("kabanight1")) {
try {
myWallpaperManager.setResource(R.drawable.madina1);
myCurrentImageName = "madina1";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("madina1")) {
try {
myWallpaperManager.setResource(R.drawable.madina2);
myCurrentImageName = "madina2";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("madina2")) {
try {
myWallpaperManager.setResource(R.drawable.kabaday1);
myCurrentImageName = "kabaday1";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("kabaday1")) {
try {
myWallpaperManager.setResource(R.drawable.uhud1);
myCurrentImageName = "uhud1";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("uhud1")) {
try {
myWallpaperManager.setResource(R.drawable.bus);
myCurrentImageName = "bus";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("bus")) {
try {
myWallpaperManager.setResource(R.drawable.muzdalifah);
myCurrentImageName = "muzdalifah";
} catch (IOException e) {
e.printStackTrace();
}
} else if (myCurrentImageName.equals("muzdalifah")) {
try {
myWallpaperManager.setResource(R.drawable.tentcity);
myCurrentImageName = "tentcity";
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
myWallpaperManager.setResource(R.drawable.madina1);
myCurrentImageName = "madina1";
} catch (IOException e) {
e.printStackTrace();
}
} // End if myCurrentImageName.equals("kabaday1").
} // End if bln_checkbox_changing_is_activated == true.
editor.putString("current_image", myCurrentImageName); // value to store
editor.commit();
} // End method onReceive.