【发布时间】:2019-09-25 13:23:27
【问题描述】:
尝试实现 WrapLayout 以允许以干净的水平添加格式添加动态按钮,如“目标”图片所示。然而,从“当前”中可以看出,WrapLayout 中按钮的大小远非理想。
通过简单的试验和错误发现,在任何元素(scrollView、wrapLayout、按钮)中使用高度和宽度请求都不会改变按钮格式。
HeightRequest = xx;
WidthRequest = xx;
到目前为止,我发现改变 wrapLayout 元素大小的唯一方法是添加大量子元素,例如:
如图所示,我对如何格式化 WrapLayout 子级的理解相当缺乏。那么,如何格式化每行允许的子级数量以及如何正确格式化 WrapLayout 的子级?
按照Xamarin Developer Sample for WrapLayout 中所示的 WrapLayout 类开发的当前实现
ScrollView scrollView = new ScrollView {
Margin = new Thickness(20, 20, 20, 20),
};
WrapLayout wrapLayout;
wrapLayout = new WrapLayout {
ColumnSpacing = 12,
};
scrollView.Content = wrapLayout;
wrapLayout.Children.Add(
new Button
{
Text = "9 ° (?)",
BackgroundColor = Color.Yellow,
BorderColor = Color.Black,
}
);
wrapLayout.Children.Add(
new Button
{
Text = "10.5 ° (?)",
BackgroundColor = Color.Gray,
BorderColor = Color.Black,
}
);
【问题讨论】:
-
您可以设置 HeightRequest,也可以将 Vertical Options 设置为在 Button Children 中启动
-
@BrunoCaceiro 太棒了!这更接近了。见
ColumnSpacing和RowSpacing,但是如何设置列数、行数?`
标签: xamarin layout xamarin.forms