[英]Xamarin Forms RelativeLayout Using
我在我的应用程序的列表页面上使用了 FloatingActionButton,我还想添加一个搜索栏。 但我无法向他们展示该页面。 我的代码和屏幕截图已关闭。 如何显示搜索栏?
FAB Github
我的代码:
<ContentPage.Content>
<RelativeLayout>
<SearchBar
x:Name="searchBar"
Placeholder="Ara"
/>
<ContentView
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}">
<ListView
x:Name="list"
BackgroundColor="White">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell
Text="{Binding .}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentView>
<fab:FloatingActionButton
x:Name="fabBtn"
Source="plus.png"
Size="Normal"
Clicked="Handle_FabClicked"
NormalColor="Green"
RippleColor="Red"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1, Constant=-75}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1, Constant=-75}" />
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
@Cheesebaron 是正确的。 问题是因为视图是相互重叠的。 相反,您需要向ContentView
添加约束,使其Y
位于searchBar
下方。 考虑这样的事情:
<ContentView
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=1}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToView, Property=Height, ElementName=searchBar}" />
注意添加的RelativeLayout.YConstraint
要立足于Height
的的searchBar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.