[英]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.