[英]How can I reduce the space between text and image on a button on android
我有一个带有图像和图像下方文本的按钮,我想在 android 上减少两者之间的空间,在 iOS 上之间没有空格,这就是我所做的:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="btnApplyLeave" ContentLayout="Top,0" BackgroundColor="White" FontSize="10" TextColor="#777777"" ImageSource="applyleave.png" BorderWidth="1" BorderColor ="#ededed" Text="Apply Leave" Grid.Row="0" Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Fill" HeightRequest="{Binding Width, Source={x:Reference btnApplyLeave}}" >
<Button.CornerRadius>
<OnPlatform Android="6">
</OnPlatform>
</Button.CornerRadius>
</Button>
<Button x:Name="captureIntent" ContentLayout="Top,0" ImageSource="capturescores.png" Text="Capture Scores" TextColor="#777777 FontSize="10" BorderWidth="1" BorderColor ="#ededed" BackgroundColor="White" Grid.Row="0" Grid.Column="1" VerticalOptions="Center" HorizontalOptions="Fill" HeightRequest="{Binding Width, Source={x:Reference captureIntent}}" >
<Button.CornerRadius>
<OnPlatform Android="6">
</OnPlatform>
</Button.CornerRadius>
</Button>
</Grid>
我不确定如何使用单个按钮来完成,但您可以使用 TapGestureRecognizer 制作一个框架,该框架就像一个按钮。 TapGestureRecognizer 既有 Tapped(如点击按钮)和 MVVM 的命令。 代码需要在您的项目中进行一些调整,但您明白了:
<Frame HeightRequest="{Binding yourHeight}" CornerRadius="6" HasShadow="false"
BackgroundColor="White" BorderColor="#ededed" HorizontalOptions="Fill">
<Frame.GestureRecognizers>
<TapGestureRecognizer />
</Frame.GestureRecognizers>
<Image Source="image.png" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label Text="TestText" HorizontalOptions="Center" VerticalOptions="Center"/>
</Frame>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.