【发布时间】:2023-03-22 07:05:01
【问题描述】:
我有以下使用 Xamarin Forms Labs 的 Xaml。图片太小,文字居中。我试图让图像更大一点,但 ImageHeightRequest 属性似乎没有影响。我还尝试了 StackLayout 格式的几种组合,例如 StackLayout 上的 HorizontalOptions="StartAndExpand" 以及元素。这会导致按钮被挤压到左侧,并且宽度不足以显示按钮的整个文本。有谁知道如何用更大的图像实现这一点,并且所有东西都与左边对齐?我知道图像更大,因为我将它从 Windows Phone 移植到 Xamarin,并且相同的图像在 Windows Phone 上更大。我也尝试过使用常规的 Xamarin Forms Image Button,它呈现相同大小的图像
<StackLayout Spacing="0" >
<Label>
<Label.FormattedText>
<FormattedString>
<FormattedString.Spans>
<Span Text="My Label" ForegroundColor="#5C85FF" Font="Large"/>
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
</Label>
<controls:ImageButton Text="Button 1" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image1.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ScanProductClicked" />
<controls:ImageButton Text="Button 2" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image2.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ShopProductsClicked" />
<controls:ImageButton Text="Button 3" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image3.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="ShoppingListsClicked" />
<controls:ImageButton Text="Button 4" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image4.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="LogInClicked" />
<controls:ImageButton Text="Button 5" BackgroundColor="#5C85FF" TextColor="#ffffff" HeightRequest="90" WidthRequest="175" Image="Image5.png" Orientation="ImageToLeft" ImageHeightRequest="85" ImageWidthRequest="100" Clicked="SettingsClicked" /> </StackLayout>
【问题讨论】:
-
你发现了吗?
-
我放弃了
ImageButton。相反,我决定使用Image并通过实现TapGestureRecognizer使其可点击。 -
我认为最新的 Xamarin.Forms 使图像按钮开箱即用。 Adam J Wolf 有一篇关于这个主题的短文:syntaxismyui.com/xamarin-forms-button-nugget。不幸的是,我不确定您对大小、位置等的控制程度
-
感谢大家的cmets!
-
@Joe 我试过了,但图像的大小也不起作用。看起来它是一个内部带有图像的按钮。所以尺寸只是影响按钮而不是图像
标签: xamarin xamarin.forms