[英]Xamarin Forms Relative Layout won't stack
使用以下代码:
<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中添加了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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.