Xamarin 表单:AbsoluteLayout

Xamarin Forms: AbsoluteLayout

我需要为此处未列出的页面上的其他控件使用 AbsoluteLayout。我如何布局一个常见的 senerio,其中我在顶部有一个 SearchBar,然后是一个 ListView 填充屏幕的其余部分。

我试过了,但是 ListView 不正确 之下 SearchBar

    <AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <SearchBar></SearchBar>
        <ListView 
            AbsoluteLayout.LayoutFlags="All"
            AbsoluteLayout.LayoutBounds="0,0,1,1">
        </ListView>
      </AbsoluteLayout>    

部分问题是您在列表视图上设置的 AbsoluteLayoutFlags。

当您将其设置为全部时,您是在告诉布局从 0,0 开始,一直到 1,1。这就是列表视图出现在搜索栏上的原因。

<AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <SearchBar AbsoluteLayout.LayoutBounds="0,0,1,40"
               AbsoluteLayout.LayoutFlags="WidthProportional,PositionProportional"/>
    <ListView 
        AbsoluteLayout.LayoutFlags="XProportional,SizeProportional"
        AbsoluteLayout.LayoutBounds="0,40,1,1">
        <ListView.ItemsSource>
            <x:Array Type="{x:Type x:String}">
                <x:String>mono</x:String>
                <x:String>monodroid</x:String>
                <x:String>monotouch</x:String>
                <x:String>monorail</x:String>
                <x:String>monodevelop</x:String>
                <x:String>monotone</x:String>
                <x:String>monopoly</x:String>
                <x:String>monomodal</x:String>
                <x:String>mononucleosis</x:String>
            </x:Array>
        </ListView.ItemsSource>
    </ListView>
</AbsoluteLayout>

Xamarin Documentation

我确定您参考的是文档。我在这里链接并引用了其中的一部分。希望它有所帮助。

Proportional values define a relationship between a layout and a view. This relationship defines a child view's position or scale value as a proportion of the corresponding value of the parent layout. These values are expressed as doubles with values between 0 and 1.

Proportional values are used to position and size views within the layout. So, when a view's width is set as a proportion, the resultant width value is the proportion multiplied by the AbsoluteLayout's width. For example, with an AbsoluteLayout of width 500 and a view set to have a proportional width of .5, the rendered width of the view will be 250 (500 x .5).