积极答复者
Windows Phone 8.1 使用GridView水平布局显示固定个数,如何自适应屏幕

问题
-
如题,我使用GridView水平布局,一行显示4个,一共4行16个,可是发现有几个尺寸不能自适应,如下
4inch-WVGA 5.5inch-1080P
4inch-WVGA和4.7inch720P显示效果是一样的(吐槽下,还不能超过两张图片,微软是有多吝啬啊),发现5inch段和4inch段宽度不一样了,6inch段的就更别说了。
下面是我的代码:
<GridView Margin="0,50,0,0" Grid.Row="1" x:Name="gvCity" ItemsSource="{Binding HotCities}" HorizontalAlignment="Left" VerticalAlignment="Center" Header="热门城市" FontSize="20" IsItemClickEnabled="True" ItemClick="gvCity_ItemClick"> <ItemsControl.ItemContainerTransitions> <TransitionCollection> <EntranceThemeTransition/> <RepositionThemeTransition/> </TransitionCollection> </ItemsControl.ItemContainerTransitions> <GridView.ItemTemplate> <DataTemplate> <Button Content="{Binding District}" FontSize="14" Style="{StaticResource ButtonTileStyle}"/> </DataTemplate> </GridView.ItemTemplate> <GridView.ItemContainerStyle> <Style TargetType="GridViewItem"> <Setter Property="Opacity" Value="0.7"></Setter> <Setter Property="Background" Value="{ThemeResource PhoneAccentBrush}"></Setter> <Setter Property="BorderBrush" Value="{ThemeResource PhoneAccentBrush}"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="Margin" Value="6"/> <Setter Property="MinWidth" Value="90"/> <Setter Property="MinHeight" Value="90"/> </Style> </GridView.ItemContainerStyle> </GridView>
windows phone8.1的布局是根据当前窗口的宽度来?一套布局无法在所有windos phone设备上正常显示?
4inch-WVGA的Bounds是400,5.5inch-720P的Bounds是450
难道需要根据这个来动态显示宽度?那么宽度480的基准分辨率有什么用?
- 已编辑 烧点饭 2014年12月26日 4:23 补充
答案
-
可能是需要对个别情况单独设置主题,像这个文章里面类似:http://developer.nokia.com/resources/library/Lumia/code-examples/dynamic-layout-sample.html
The inclusion of big screen optimised styles is determined by StyleSelector class:
... class StyleSelector { static public void SetStyle() { if(ScreenSizeHelper.IsBigScreen) { var appTheme = new ResourceDictionary { Source = new Uri("/DynamicLayoutSample;component/Themes/SampleDataItemStyle1080p.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(appTheme); } } } ...
- 已编辑 iDotNeter 2014年12月29日 6:47
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2015年1月5日 10:52
全部回复
-
可能是需要对个别情况单独设置主题,像这个文章里面类似:http://developer.nokia.com/resources/library/Lumia/code-examples/dynamic-layout-sample.html
The inclusion of big screen optimised styles is determined by StyleSelector class:
... class StyleSelector { static public void SetStyle() { if(ScreenSizeHelper.IsBigScreen) { var appTheme = new ResourceDictionary { Source = new Uri("/DynamicLayoutSample;component/Themes/SampleDataItemStyle1080p.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(appTheme); } } } ...
- 已编辑 iDotNeter 2014年12月29日 6:47
- 已标记为答案 Franklin ChenMicrosoft employee, Moderator 2015年1月5日 10:52
-
可能是需要对个别情况单独设置主题,像这个文章里面类似:http://developer.nokia.com/resources/library/Lumia/code-examples/dynamic-layout-sample.html
The inclusion of big screen optimised styles is determined by StyleSelector class:
... class StyleSelector { static public void SetStyle() { if(ScreenSizeHelper.IsBigScreen) { var appTheme = new ResourceDictionary { Source = new Uri("/DynamicLayoutSample;component/Themes/SampleDataItemStyle1080p.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(appTheme); } } } ...