我在应用程序的列表页面上使用FloatingActionButton,我也想添加一个searchBar。但我无法向他们显示该页面。我的代码和屏幕截图已关闭。如何显示searchBar?
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
。关于android - Xamarin使用以下形式形成RelativeLayout,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41505487/