简体   繁体   English

如何减少 android 上按钮上的文本和图像之间的空间

[英]How can I reduce the space between text and image on a button on android

在此处输入图像描述 I have a button that has an image and a text below the image, I want to reduce the space between the two on android, on iOS there is no spaces in between, here is what I have done:我有一个带有图像和图像下方文本的按钮,我想在 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>

I'm not sure about how to do it with a single button, but you could make a frame with a TapGestureRecognizer that will act like a button.我不确定如何使用单个按钮来完成,但您可以使用 TapGestureRecognizer 制作一个框架,该框架就像一个按钮。 The TapGestureRecognizer have both Tapped (like clicked on button) and Command for MVVM. TapGestureRecognizer 既有 Tapped(如点击按钮)和 MVVM 的命令。 The code needs some adjustment in your project, but you get the idea:代码需要在您的项目中进行一些调整,但您明白了:

    <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>

I found this issue is realted to the ContentLayout in the android platform.我发现这个问题与 android 平台中的ContentLayout有关。

在此处输入图像描述

If I set the value of spacing to -200 in the android Platform We can reduce the spacing.如果我在 android 平台中将spacing的值设置为-200我们可以减小间距。

if (Device.RuntimePlatform == Device.Android)
        {
            btnApplyLeave.ContentLayout = new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Top, -200);
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM