简体   繁体   中英

Xamarin.forms custom button control

i need to reduce space between buttons 在此处输入图片说明

i used buttons for side bar, didn't use list view, if i set height request to reduce the height text will be overlapping, is the any way to reduce height using custom render or other way ?

this is my code

            <!--<Grid BackgroundColor="#783271"  VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="20"/>

                </Grid.RowDefinitions>

                <Button Grid.Column="0"  Grid.Row="0" Text="Client Expertential Plan" TextColor="#636363" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" BorderWidth="0" BackgroundColor="White" FontSize="Small" FontAttributes="Italic"/>
                <Button Grid.Column="0"  Grid.Row="1" Text="Organisation / Template Library" TextColor="#636363" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>
                <Button Grid.Column="0"  Grid.Row="2" Text="Use Expertential Plan" TextColor="#636363" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>

            </Grid>-->

            <!--<local:CustomButton Text="hai"></local:CustomButton>-->
            <Button Text="Client Expertential Plan" TextColor="#636363" VerticalOptions="FillAndExpand" HorizontalOptions="Start" BorderWidth="0" BackgroundColor="White" FontSize="Small" FontAttributes="Italic"/>
            <Button Text="Organisation / Template Library" TextColor="#636363" VerticalOptions="FillAndExpand" HorizontalOptions="Start" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>
            <Button Text="Use Expertential Plan" TextColor="#636363" VerticalOptions="FillAndExpand" HorizontalOptions="Start" BorderWidth="0" BackgroundColor="White" FontSize="Small"  FontAttributes="Italic"/>
            <!--<Label x:Name="lblClientExpPlan"  Text="Client Expertential Plan" TextColor="#737373" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand"/>
            <Label  x:Name="lblOrgTemLib" Text="Organisation / Template Library" TextColor="#737373" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand"/>
            <Label  x:Name="lblUseExpPlan" Text="Use Expertential Plan" TextColor="#737373" VerticalOptions="FillAndExpand" HorizontalOptions="StartAndExpand"/>-->
        </StackLayout> 

A simple solution is to use the HeightRequest property as you mention but also reduce the Padding. Android buttons have a large HeightRequest and Padding compared to iOS by default. Try the following:

<StackLayout.Resources>
    <ResourceDictionary>
        <Style TargetType="Button" >
            <Setter Property="HeightRequest" Value="30" />
            <Setter Property="Padding" Value="10, 5" />
            <Setter Property="FontSize" Value="Small" />
            <Setter Property="BorderWidth" Value="0" />
            <Setter Property="VerticalOptions" Value="Start" />
            <Setter Property="HorizontalOptions" Value="Start" />
            <Setter Property="BackgroundColor" Value="White" />
            <Setter Property="TextColor" Value="#636363" />
            <Setter Property="FontAttributes" Value="Italic" />
        </Style>
    </ResourceDictionary>
</StackLayout.Resources>

<Button Text="Client Expertential Plan" />
<Button Text="Organisation / Template Library" />
<Button Text="Use Expertential Plan" />

The padding property is a recent addition to the Button control. It is present in the Xamarin.Forms 3.2 pre-releases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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