C# Xamarin表单相对布局赢得';t堆栈
使用以下代码:C# Xamarin表单相对布局赢得';t堆栈,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,使用以下代码: <ScrollView Orientation="Vertical" Padding="0"> <RelativeLayout BackgroundColor="Red" Padding="0"> <BoxView Color="Blue" WidthRequest="100" HeightRequest="100" RelativeLayout.XConstr
<ScrollView Orientation="Vertical" Padding="0">
<RelativeLayout BackgroundColor="Red" Padding="0">
<BoxView Color="Blue" WidthRequest="100" HeightRequest="100"
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" />
</RelativeLayout>
<RelativeLayout BackgroundColor="Green" Padding="0">
<BoxView Color="Yellow" WidthRequest="100" HeightRequest="100"
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" />
</RelativeLayout>
</ScrollView>
但出于某种原因,每个新的相对布局都会像这样占据整个屏幕,而不是堆叠:
为什么它们不会垂直堆叠?堆栈布局通常只取其子级的垂直或水平组合高度,但相对布局不会出现这种情况。我缺少什么?试试这个布局。我在ScrollView和VerticalOptions=“Start”中为RelativeLayouts添加了StackLayout
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TestChat.ChatPage">
<ContentPage.Content>
<ScrollView Orientation="Vertical" Padding="0">
<StackLayout>
<RelativeLayout BackgroundColor="Red" Padding="0" VerticalOptions="Start">
<BoxView Color="Blue" WidthRequest="100" HeightRequest="100"
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" />
</RelativeLayout>
<RelativeLayout BackgroundColor="Green" Padding="0" VerticalOptions="Start">
<BoxView Color="Yellow" WidthRequest="100" HeightRequest="100"
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" />
</RelativeLayout>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
StackLayout FTW。我基本上只使用它和网格(SL开发者日时间)