【发布时间】:2019-04-16 18:37:59
【问题描述】:
按照本页示例 - https://devlinduldulao.pro/how-to-create-a-floating-action-button/
,我正在尝试让SuaveControls.FloatingActionButton 在 ListView 之上工作
我的ListView 在StackLayout 中,所以我决定将它们包装到AbsoluteLayout 中
这里是视图/XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:SuaveControls.Views;assembly=SuaveControls.FloatingActionButton"
xmlns:local="clr-namespace:DPM.XForms"
x:Class="DPM.XForms.ProjectListPage"
Title="Drive Plus Mobile"
>
<AbsoluteLayout>
<StackLayout Orientation="Vertical" Spacing="1">
<Label Text="TopBar ..." BackgroundColor="Gray" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Center"/>
<!-- Project Search/Filter toolbar-->
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" Padding="7" BackgroundColor="White">
<Label Text="Projects " TextColor="DarkGray" Font="Bold,17" HorizontalOptions="Center" VerticalOptions="Center"/>
<StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand" Padding="0">
<Button Image="Search.png" BackgroundColor="White" WidthRequest="27" HeightRequest="27"></Button>
<Button Image="LeftBS.png" BackgroundColor="White" WidthRequest="27" HeightRequest="27"></Button>
<Button Image="CenteredBS.png" BackgroundColor="White" WidthRequest="27" HeightRequest="27"></Button>
<Button Text="++" WidthRequest="27" HeightRequest="27" Clicked="CreateProject_Clicked"></Button>
</StackLayout>
</StackLayout>
<Label Text="Pin projects" HorizontalOptions="FillAndExpand" HorizontalTextAlignment="Center" BackgroundColor="LightGray" HeightRequest="25" />
<ListView x:Name="lvProjects" ItemTapped="OnProjectTapped" RowHeight="54" BackgroundColor="DarkGray">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<!-- Project Row -->
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" BackgroundColor="White" Margin="0,1,0,1" >
<Button
Image="Colombia.png"
BackgroundColor="White"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="54"
HeightRequest="54"
>
</Button>
<StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand">
<Label
Text="{Binding Name}"
TextColor="Black"
Font="Bold,17"
HorizontalOptions="StartAndExpand"
VerticalOptions="Start"
/>
<Label
Text="{Binding Brand}"
TextColor="Black"
HorizontalOptions="Start"
VerticalOptions="Start"
/>
<Label
Text=".."
TextColor="Black"
HorizontalOptions="Start"
VerticalOptions="End"
/>
</StackLayout>
<Button Text="3" WidthRequest="44"></Button>
<Button Text=">" WidthRequest="44" BackgroundColor="White" ></Button>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<views:FloatingActionButton
Image="CreateProject.png"
WidthRequest="80"
HeightRequest="80"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Clicked="FloatingActionButton_Clicked"
>
</views:FloatingActionButton>
</AbsoluteLayout>
</ContentPage>
但是使用这种方法会发生两件事
- 当设备处于横向模式时,
ListView不会像添加AbsoluteLayout之前那样增长
- 不知道如何定位
FloatingActionButton以始终保持在任何设备的右下角
我也尝试将 FloatingActionButton 放在当前 StackLayout 中,但它不会浮动,只是添加到列表视图的下方或上方,就像这里显示的常规“行”一样
如果有不清楚的地方,请随意使用 cmets。
【问题讨论】:
标签: android listview xamarin floating-action-button