【问题标题】:How to manage different screen resolution in wp7?如何在 wp7 中管理不同的屏幕分辨率?
【发布时间】:2012-12-26 05:00:53
【问题描述】:

我想知道在 windows phone 7 中开发应用程序时处理不同屏幕分辨率的最佳方法是什么。

因为我以 480 x 800 像素开发所有应用程序,而且我知道并非所有移动设备都支持 480 x 800 像素分辨率。

如果我在 xaml 中硬编码宽度、高度、边距等,那么当手机不支持 480x800 分辨率时就会出现问题。

那么在单个应用程序中管理所有分辨率的最佳方法是什么?就像在 android 中有不同的文件夹用于不同的分辨率(Hdpi,Ldpi)。

帮帮我

【问题讨论】:

  • WP8 Emulator screen size 的可能重复项
  • 是的,wp7 不支持不同的解决方案,但 wp8 支持这个,据我所知 wp8 有非常复杂的分辨率方法。假设我在不同的页面中有 100 个图像,所以我必须使用 300 个“如果“条件。这很复杂。还有其他最好的解决方案吗?

标签: windows-phone-7 windows-phone-8 screen-resolution


【解决方案1】:

请阅读我之前关于该主题的回答:Zen of WP8 Multi-resolution supportAPIs for WP8 mutli-resolutionDevCenter multiple XAP supportWP7 & WP8 co-development guide

具体看看WP7 & WP8 co-development guide under Runtime adaption。那有这个代码sn-p:

public Uri GetScaledImageUri(String imageName) 
{
    int scaleFactor = (int)Application.Current.Host.Content.ScaleFactor;
    switch (scaleFactor)
    {
        case 100: return new Uri(imageName + "_wvga.png", UriKind.RelativeOrAbsolute);
        case 150: return new Uri(imageName + "_720p.png", UriKind.RelativeOrAbsolute);
        case 160: return new Uri(imageName + "_wxga.png", UriKind.RelativeOrAbsolute);
        default:  throw new InvalidOperationException("Unknown resolution type");
    }
}

// Next line will load a correct image depending on the resolution of the device
MyImage.Source = new BitmapImage(GetScaledImageUri("myImage"));

还可以看看APIs for WP8 mutli-resolution 有这三个互斥代码sn-ps:

Image myImage = new Image();
if (MultiRes.Is720p)
    myImage.Source = new BitmapImage(new Uri("puppies.720p.jpg"));
else if (MultiRes.IsWvga)
    myImage.Source = new BitmapImage(new Uri("puppies.wvga.jpg"));
else if (MultiRes.IsWxga)
    myImage.Source = new BitmapImage(new Uri("puppies.wxga.jpg"));

if (MultiRes.Is720p)
    myImage.Source = new BitmapImage(new Uri(@"assets\16by9AspectRatio\puppies.jpg"));
else
    myImage.Source = new BitmapImage(new Uri(@"assets\15by9AspectRatio\puppies.jpg"));

if (MultiRes.IsHighResolution)
    myImage.Source = new BitmapImage(new Uri(@"assets\HD\puppies.jpg"));
else
    myImage.Source = new BitmapImage(new Uri(@"assets\SD\puppies.jpg"));

【讨论】:

  • JustinAngel:谢谢,你的意思是 wp7 只支持 480x800 像素分辨率?
  • 是的,这很好,但我想在同一个项目中使用不同的分辨率,那么图像文件夹以及如何根据不同的分辨率应用不同的图像和网格或堆栈面板大小
  • 您必须自己编写代码才能根据分辨率更改图像。您可以制定自己的文件和文件夹名称约定。同样,请参阅链接文章中“运行时适应”下的代码示例,特别是方法“GetScaledImageUri”。
  • 是的,WP7 平台仅支持 WVGA (480x800),因此即使在 WP8 上,WP7 应用也只能以 15:9 纵横比的 480x800 逻辑像素运行。一旦应用重新编译为 WP8,应用就可以支持 16:9 的纵横比。请阅读所附文章。但是,在 WP8 WXGA/720P 上运行的 WP7 应用程序的图像和视频位图会被缩放,这可能看起来不太好。
  • :谢谢,但我认为当我拥有超过 10 个图像控件而不是必须应用 30 个条件时,它非常复杂?并且所有图像都适用于编码部分? xaml 方面的工作是什么?
【解决方案2】:

在 wp8 中开发应用程序时,我得到了处理不同屏幕分辨率的解决方案。

JustinAngel 分析器也是正确的,但它有些复杂,因为它包含大量需要维护的代码,而且有些困难。

因此,请使用 Telerik RedControls。无需维护代码隐藏,并且可以通过简单直接的方式根据分辨率加载不同的图像。

请参考此链接

Multi-Resolution support in Windows Phone 8 Made Easy

希望这对所有 wp8 开发人员有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    • 1970-01-01
    • 2015-07-22
    • 2017-10-09
    相关资源
    最近更新 更多