【发布时间】:2019-08-20 18:10:00
【问题描述】:
我想要的是两个并排的图像按钮,它们与屏幕底部的屏幕宽度相匹配。无论屏幕大小,我都希望纵横比相同。
I want it to look something like this
我尝试使用 Grid 来实现这一点。我有 2 个具有相同源图像的 ImageButton 元素。问题是当这些图像被调整为网格行的高度时,它们不会包裹新的图像高度,当它们被调整大小时,它们不会填满整个屏幕宽度。在这两种情况下,网格似乎都采用原始图像的高度。
Screen 1440 x 2960 in preview, when image is scaled down, grid height is bigger than it should be.
XAML:
<StackLayout
Spacing="0">
<StackLayout
VerticalOptions="Start">
</StackLayout>
<StackLayout
VerticalOptions="CenterAndExpand">
</StackLayout>
<StackLayout
Orientation="Horizontal"
BackgroundColor="Bisque"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Grid x:Name="grid"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
ColumnSpacing="0"
RowSpacing="0">
<ImageButton
x:Name="imageButton"
Source="key1.png"
Grid.Row="0"
Grid.Column="0"/>
<ImageButton
Source="key1.png"
Grid.Row="0"
Grid.Column="1" />
</Grid>
</StackLayout>
我找到了缩小图像大小时的解决方法:
imageButton.SizeChanged += (o, e) =>
{
grid.RowDefinitions.Clear();
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(imageButton.Height, GridUnitType.Absolute) });
};
但这不是我想要的解决方案(特别是因为它在这两种情况下都不起作用)。我错过了什么?这应该很简单。这可能不是网格问题而是其他问题?我怎样才能做到这一点?
【问题讨论】:
标签: xaml xamarin grid scale imagebutton