我是Xamarin表单的新手,并有一个基本问题,以找出在Xamarin表单中使用带有图像和文本的按钮的最佳方法。
任务是设计具有如下按钮布局的主页:
我能够使用Buttons和StackLayout完成此布局。我使用Button的ContentLayout属性设置对齐方式(例如):
以这种方式图像向右移动,并且间距定义了文本和图像之间的空间。我必须为似乎错误的每个按钮设置不同的间距。我没有找到任何更好的方法来将Text设置为左对齐,并且默认情况下它似乎居中对齐。
是否有Button的任何属性,可用于使按钮文本左对齐。或者,采用这种基本设计的更好的方法是什么。
我认为按钮没有其他方法,但是在您的情况下,我建议您使用Button中的ContentLayout属性使用StackLayout without,因为您总是需要在最后显示按钮。] >
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="10">
<Label Text="Small Text" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand"/>
<Image Source="image.png" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand"/>
</StackLayout>
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="10">
<Label Text="This is large text" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand"/>
<Image Source="image.png" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</StackLayout>