Xamarin表格相对布局不会叠加

sga*_*dev 3 c# xaml xamarin xamarin.forms

使用以下代码:

<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>
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,每个新的相对布局不是堆叠,而是占用整个屏幕,如下所示:

在此输入图像描述

他们为什么不垂直叠加?堆栈布局通常仅垂直或水平地采用其子项的组合高度,但相对布局不会发生这种情况.我错过了什么?

Art*_*nov 6

试试这个布局.我在ScrollView中添加了StackLayout,为RelativeLayouts添加了VerticalOptions ="Start".

<?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>
Run Code Online (Sandbox Code Playgroud)