【发布时间】:2018-02-21 10:09:33
【问题描述】:
我试图在FlowListView 中每行放置三个二次帧。
xaml:
FlowListView代码:
<toolkit:FlowListView
FlowColumnCount="3"
HasUnevenRows="True"
FlowRowBackgroundColor="{Binding WidgetMainColor}"
Margin="10,0,10,0"
FlowItemsSource="{Binding TestContainer.WidgetsInContainer}">
<toolkit:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Frame
Margin="5"
WidthRequest="{Binding WidthAndHeightForDashboard}"
HeightRequest="{Binding WidthAndHeightForDashboard}"
BackgroundColor="{Binding WidgetMainColor}"
CornerRadius="2"
HasShadow="False"/>
</DataTemplate>
</toolkit:FlowListView.FlowColumnTemplate>
</toolkit:FlowListView>
计算框架的宽度/高度:
WidthAndHeightForDashboard:
public double WidthAndHeightForDashboard
{
get
{
// -50 for Margin (6 * 5 for Frame margins, 2 * 10 for FlowListView margin)
// rest is divided by 3 because we need 3 frames
return (double)(App.ScreenWidth - 50) / 3;
}
}
我使用ScreenWidth 来计算WidthAndHeightForDashboard,因为我知道页面将始终处于纵向模式。这意味着我们在此页面上的高度将大于宽度,因此宽度对于二次框架来说是决定性的。
ScreenWidth 是这样计算的:
App.ScreenWidth = (int)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);
我的结果的屏幕截图
正如您在屏幕截图中看到的那样,帧的高度大于宽度,但它们应该是二次的:
我还尝试删除所有边距并从计算中删除边距,以防我的计算出现错误,但这并不能解决问题。
WidthRequest 和 HeightRequest 使用相同的值,但帧的高度大于宽度,所以我很确定 WidthAndHeightForDashboard 的计算值高于应有的值...或者可能存在App.ScreenWidth 所说的屏幕上的空间是否更少?
【问题讨论】:
-
App.ScreenWidth是否给出了正确的行为?移动平台上有多种尺寸概念,如果出现偏差,这可能是您问题的根源。加载后查看FlowListView的宽度。
标签: xaml listview xamarin xamarin.forms