xamarin.forms - SkiaSharp 矩形的大小比 iOS 上的小
问题描述
我用 SkiaSharp 绘制位置 x、y、宽度和高度的列表项。这在 Android 中没问题,但在 iOS 中布局和大小项目较小。请查看以下代码和图像以了解:
在 Xaml 中:
<ContentPage.Content>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" BackgroundColor="White">
<Grid Padding="20">
<skia:SKCanvasView x:Name="canvasView"
PaintSurface="SKCanvasView_PaintSurface" BackgroundColor="Beige"/>
</Grid>
</StackLayout>
</ContentPage.Content>
在视图中:
private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
{
try
{
int NumberColums = 10;
int NumberRows = 9;
Size m_CurrentTableSize = new Size();
canvasView.WidthRequest = this.Width; //width of page
canvasView.HeightRequest = this.Height;//height of page
var canvas = e.Surface.Canvas;
var widthView = Width;
var heightView = Height;
m_CurrentTableSize = new Size(widthView / NumberColums, heightView / NumberRows);
ObservableCollection<Table> Tables = _viewModel.Tables;
for (int i = 0; i < Tables.Count; i++)
{
Table tableModel = Tables[i];
int row = tableModel.PositionY;
int col = tableModel.PositionX;
int height = tableModel.Height;
int width = tableModel.Width;
var dH = (float)m_CurrentTableSize.Height / 68;
var dW = (float)m_CurrentTableSize.Width / 68;
row = (int)(dH * (float)row);
col = (int)(dW * (float)col);
height = (int)(height * dH);
width = (int)(width * dW);
var minSize = Math.Min(height, width);
tableModel.Height = (int)minSize;
tableModel.Width = (int)minSize;
canvas.DrawRoundRect(new SKRoundRect(new SKRect((float)col, (float)row, (float)col + (float)tableModel.Height, (float)row + (float)tableModel.Width)), GetColor(tableModel.Status));
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
在Android显示正常:
在 iOS 中,布局不完整:
感谢您的意见。
解决方案
尝试为网格设置 FillAndExpand。像这样
<Grid Padding="20" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
推荐阅读
- python-3.x - 使用python解码字符串|| SHA256
- sql - Postgres递归查询-给定叶节点获取根路径
- javascript - 如何发送 Twilio 连接并在 Twilio Client Javascript SDK 的另一个功能中接受它?
- node.js - React-Router 5 和 Express - 包罗万象的路由后备
- jquery - jQuery 鼠标事件不允许移动
- flutter - 如何在容器顶部显示文本?
- python - 实现 python db 监听器的问题
- swift - 我可以编写 iCloud 文档,但看不到它们
- c++ - 我似乎无法让 msvc 链接器在 vscode 上正常工作
- excel - 如何过滤掉 Excel 行中的部分匹配项?