繁体   English   中英

Xamarin Forms RelativeLayout 使用

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM