xamarin - 按钮不适合屏幕 xamarin
问题描述
嘿,我必须在我的应用程序中添加 +20 按钮
我用这个代码
var layout = new StackLayout() {
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Start,
};
for (int i = 1; i < 20; i++)
{
var button = new Button
{
Text = i.ToString(),
HeightRequest = 45,
WidthRequest = 45,
Margin = 5,
BorderRadius = 100,
VerticalOptions = LayoutOptions.Center,
};
grid.Children.Add(button);
}
Content = layout;
}
所以现在按钮正在远离屏幕
我必须得到类似的东西
解决方案
使用FlexLayout而不是StackLayout
var layout = new FlexLayout();
for (int i = 1; i < 20; i++)
{
var button = new Button
{
Text = i.ToString(),
HeightRequest = 45,
WidthRequest = 45,
Margin = 5,
BorderRadius = 100,
VerticalOptions = LayoutOptions.Center,
};
layout.Children.Add(button);
}
Content = layout;
推荐阅读
- django - Django REST Framework - 将额外参数传递给操作
- java - 如何在 libgdx-InputProcess 中使用放大功能?
- c# - 使用 oledb 在 c# 中获取访问数据范围
- javascript - 如何将 2 个 javascript 数组从 laravel 视图传递到 laravel 控制器?
- ios - 如何在按钮单击时在一个视图控制器上显示不同的视图
- angularjs - 使用 ng-repeat 创建一个包含 1…N 的列标题数组
- java - 匿名类中的执行顺序
- javascript - 涉及滑块的奇怪错误
- java - 打印非托管 Spring bean 名称
- matlab - 如何读取文本文件中的信息以绘制数据?MATLAB