壁纸图像在所有设备上都没有以正确的尺寸显示

时间:2011-11-02 13:33:14

标签: android image scale android-wallpaper

我做了一个应用程序,按时间间隔使用几个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.

3 个答案:

答案 0 :(得分:0)

图像的渲染取决于以下内容:

屏幕尺寸

屏幕密度

分辨率

您应该更好地阅读以下文档,了解如何处理这种情况: Supporting Multiple Screens

答案 1 :(得分:0)

myWallpaperManager这个imageView应该是fill_parent。 RU给出了任何固定的大小?

答案 2 :(得分:0)

添加以显示此权限<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/> <uses-permission android:name="android.permission.SET_WALLPAPER" />