我有问题。我创建了一个示例项目来解决它,但没有成功。 我在导航栏的中间创建了一个具有负边距的按钮。 水龙头仅在下部起作用。
MainPage.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="HelloWorld.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Frame HeightRequest="56"
Margin="0"
Padding="0"
BackgroundColor="Yellow" />
<Grid>
<Frame WidthRequest="56"
HeightRequest="56"
Margin="0,-28,0,0"
Padding="0"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="Blue"
CornerRadius="28">
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Frame.GestureRecognizers>
</Frame>
</Grid>
</Grid>
</Grid>
</ContentPage>
Xamarin.Forms:4.2.0.815419
答案 0 :(得分:1)
新编辑
<?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" mc:Ignorable="d" x:Class="helloworld.MainPage">
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<ListView Grid.Row="0" BackgroundColor="Red"/>
<Frame Grid.Row="1" BackgroundColor="Yellow" Padding="0">
</Frame>
<Grid Grid.Row="1" TranslationY="-28">
<Frame WidthRequest="56"
HeightRequest="56"
Margin="0"
Padding="0"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="Blue"
CornerRadius="28">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped" />
</Frame.GestureRecognizers>
</Frame>
</Grid>
</Grid>
</ContentPage>
修改
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="HelloWorld.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<RelativeLayout>
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView Grid.Row="0" BackgroundColor="Red" />
<Grid Grid.Row="1">
<Frame HeightRequest="56"
Padding="0"
BackgroundColor="Yellow" />
</Grid>
</Grid>
<Frame WidthRequest="56"
HeightRequest="56"
Padding="0"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="Blue"
CornerRadius="28"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=0.5,
Constant=-28}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=1,
Constant=-84}">
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Frame.GestureRecognizers>
</Frame>
</RelativeLayout>
</ContentPage>
旧的错误解决方案,它使用顶部元素创建了一个空格。
我删除了按钮上的边距,并将正边距放在另一个元素上。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="HelloWorld.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<ListView Grid.Row="0" BackgroundColor="Red"/>
<Grid Grid.Row="1">
<Frame HeightRequest="56"
Margin="0,28,0,0"
Padding="0"
BackgroundColor="Yellow" />
<Grid>
<Frame WidthRequest="56"
HeightRequest="56"
Margin="0"
Padding="0"
HorizontalOptions="Center"
VerticalOptions="Start"
BackgroundColor="Blue"
CornerRadius="28">
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Frame.GestureRecognizers>
</Frame>
</Grid>
</Grid>
</Grid>
</ContentPage>