Xamarin Forms NavigationBar 有左边距 [英] Xamarin Forms NavigationBar has left margin

查看:39
本文介绍了Xamarin Forms NavigationBar 有左边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.我创建了一个这样的 TabbedPage:

I have a problem. I created a TabbedPage like this:

TabbedBuilder = new TabbedPage
{
    BarBackgroundColor = Color.FromHex("#212121"),
    BarTextColor = Color.White
};

TabbedBuilder.Children.Add(new NavigationPage(new Builder())
{ 
    Title = "Builder",
    BarBackgroundColor = Color.FromHex("#212121")
});
TabbedBuilder.Children.Add(new NavigationPage(new TemplateList())
{
    Title = "Templates",
    BarBackgroundColor = Color.FromHex("#212121")
});

我这样称呼它:

Navigation.PushModalAsync(TabbedBuilder);

现在在 TabbedBuilder 我有这个自定义导航栏:

Now in the TabbedBuilder I have this custom navbar:

<NavigationPage.TitleView>
    <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <StackLayout VerticalOptions="CenterAndExpand" Orientation="Horizontal" BackgroundColor="#212121">
            <ImageButton Source="Back_Dark.png" HeightRequest="25" WidthRequest="35" HorizontalOptions="Start"
                VerticalOptions="Center" BackgroundColor="Transparent" Clicked="btnBack_Clicked"/>
            <Image Source="Title_Dark.png" HeightRequest="25" HorizontalOptions="CenterAndExpand" VerticalOptions="Center"/>
        </StackLayout>
        <StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand">
            <Label HeightRequest="1" BackgroundColor="White" HorizontalOptions="Fill"/>
        </StackLayout>
    </StackLayout>
</NavigationPage.TitleView>

但是左边有一小块边距!

But there is a small margin on the left side!

我怎样才能删除它?

这是完整的xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:skia="clr-namespace:SkiaSharp.Views.Forms;assembly=SkiaSharp.Views.Forms"
             xmlns:tt="clr-namespace:TouchTracking.Forms;assembly=TouchTracking.Forms"
             mc:Ignorable="d"
             x:Class="MyApp.Builder"
             BackgroundColor="#212121"
             Title="Builder">

    <NavigationPage.TitleView>
        <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <StackLayout VerticalOptions="CenterAndExpand" Orientation="Horizontal" BackgroundColor="#212121">
                <ImageButton Source="Back_Dark.png" HeightRequest="25" WidthRequest="35" HorizontalOptions="Start"
                    VerticalOptions="Center" Margin="0,0,0,0" BackgroundColor="Transparent" Clicked="btnBack_Clicked"/>
                <Image Source="Title_Dark.png" HeightRequest="25" HorizontalOptions="CenterAndExpand" VerticalOptions="Center"/>
            </StackLayout>
            <StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand">
                <Label HeightRequest="1" BackgroundColor="White" HorizontalOptions="Fill"/>
            </StackLayout>
        </StackLayout>
    </NavigationPage.TitleView>

    <ContentPage.Content>
        <StackLayout>
            <RelativeLayout VerticalOptions="FillAndExpand" x:Name="MainLayout">
                <StackLayout Orientation="Vertical" VerticalOptions="Center"
                             RelativeLayout.XConstraint=
                                    "{ConstraintExpression 
                                        Type=RelativeToParent,
                                        Property=Width, 
                                        Factor=0,
                                        Constant=0
                                        }"
                            RelativeLayout.YConstraint=
                                "{ConstraintExpression 
                                        Type=RelativeToParent,
                                        Property=Height,
                                        Factor=0.12,
                                        Constant=0}">

                    <Grid x:Name="GridUpperControl">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="50" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="10" />
                        </Grid.ColumnDefinitions>

                        <AbsoluteLayout Grid.Row="1" Grid.ColumnSpan="15" x:Name="CanvasLayout" BackgroundColor="Transparent">
                            <Grid x:Name="CanvasGrid" VerticalOptions="Center" Grid.Row="1" Grid.ColumnSpan="15">
                                <skia:SKCanvasView x:Name="Canvas" BackgroundColor="White" VerticalOptions="FillAndExpand"
                                        PaintSurface="OnCanvasViewPaintSurface" />
                                <Grid.Effects>
                                    <tt:TouchEffect Capture="True"
                                        TouchAction="OnTouchEffectAction" />
                                </Grid.Effects>
                            </Grid>
                        </AbsoluteLayout>
                    </Grid>

                    <Grid x:Name="GridBottomControl" VerticalOptions="Center" HorizontalOptions="Center">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="60"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="5" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="10" />
                        </Grid.ColumnDefinitions>
                    </Grid>
                </StackLayout>

                <StackLayout Orientation="Horizontal"
                             RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                               Property=Width,
                                                                               Factor=0.95,
                                                                               Constant=-65}"
                             RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
                                                                               Property=Height,
                                                                               Factor=0.95,
                                                                               Constant=-65}"
                             VerticalOptions="End">
                    <ImageButton
                Margin="0,0,15,15"
                BackgroundColor="Transparent"
                HeightRequest="65"
                HorizontalOptions="End"
                Source="ActionButton_Continue.png"
                WidthRequest="65" Clicked="OnContinueClicked" />
                </StackLayout>
            </RelativeLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

我不知道在哪里设置了可能导致导航栏中出现空格的填充/边距!

I have no idea where I have set a padding/margin that could cause a space in the navigation bar!

推荐答案

对于 Android,您可以手动调整 MainActivity 中的 Toolbar.

For Android you can manually tweak the Toolbar in MainActivity.

protected override void OnResume()
{
   base.OnResume();

   var toolbar = this.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
   if (toolbar != null)
   {
       toolbar.SetPadding(0, 0, 0, 0);
       toolbar.SetContentInsetsAbsolute(0, 0);
   }
}

这篇关于Xamarin Forms NavigationBar 有左边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆