
[英]Xamarin.Forms How to make centered SplashScreen fit on the screen
[英]figure out how many circular frames fit on screen xamarin.forms
我想根据 class 中的学生人数创建一个带有圆形框架的网格。 我想以每列中的帧数适合屏幕的方式显示它们,并且我将相应地添加行,所以我尝试做这样的事情作为试验:
xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="stdprofiles.MainPage">
<StackLayout Orientation="Horizontal" >
<Grid x:Name="thislayout" HorizontalOptions="Center" Margin="20,20" >
</Grid>
</StackLayout>
</ContentPage>
xaml.cs:
public MainPage()
{
InitializeComponent();
var width = DeviceDisplay.MainDisplayInfo.Width;
var height = DeviceDisplay.MainDisplayInfo.Height;
double nbofcolumns = width / 150;
double nbofrows = 10 / nbofcolumns;
double ans = nbofcolumns * nbofrows;
for (int i = 0; i < nbofcolumns-1; i++)
{
thislayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 100 });
}
for (int j=0;j< nbofrows+1; j++)
{
thislayout.RowDefinitions.Add(new RowDefinition { Height = 100 });
}
for(int i=0;i<10;i++)
{
SwipeItem delete = new SwipeItem
{
IconImageSource="deleteic.png",
BackgroundColor = Color.Transparent
};
List<SwipeItem> swipeItems = new List<SwipeItem>() { delete };
Frame circleImageFrame = new Frame
{
ClassId=i.ToString(),
Margin = 10,
BorderColor = Color.Black,
CornerRadius = 50,
HeightRequest = 100,
WidthRequest = 100,
IsClippedToBounds = true,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Content = new Image
{
Source = ImageSource.FromFile("user_profile.png"),
Aspect = Aspect.AspectFill,
Margin = -20,
HeightRequest = 100,
WidthRequest = 100
}
};
SwipeView swipe = new SwipeView
{
TopItems = new SwipeItems(swipeItems),
Content=circleImageFrame
};
thislayout.Children.Add(swipe, i%(int)nbofcolumns, i/(int)nbofcolumns);
delete.Invoked += delegate
{
thislayout.Children.Remove(swipe);
};
}
}
关键是我得到了手机屏幕的宽度,然后将其除以 150,因为我指定我希望列的宽度为 100。问题是它不起作用,获得的列数不适合我的屏幕有 7 列,只有 4 列适合 rest 没有出现,所以我没有得到正确的行数。 让我感到惊讶的另一件事是,当我尝试显示获得的宽度时,我得到了 1080(对于我的手机),但是当我使用平板电脑时,我得到了 800,尽管我的平板电脑比我的手机大。 怎么来的? 有些东西看起来很奇怪,我不知道它是什么。 有什么建议么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.