【问题标题】:How to get FAB to float over WebView in Xamarin XAML如何让 FAB 漂浮在 Xamarin XAML 中的 WebView 上
【发布时间】:2018-09-21 14:06:27
【问题描述】:

我正在尝试设置一个 XAML 表单定义,它显示一个 WebView,但右下角有一个浮动操作按钮。

如果我使用 AbsoluteLayout,FAB 会正确显示在 WebView 上。但是,由于 Webview 的 Height/WidthRequest,它以全尺寸显示 - 文本从右侧消失并且不换行,因此页面不会滚动。

<ContentPage ...snip... Title="Document">
    <StackLayout Padding="5,5,5,5" HorizontalOptions="FillAndExpand" Orientation="Vertical">
        <WebView x:Name="webViewDocument" WidthRequest="1000" HeightRequest="1000" />
        <Label Text="{Binding UpdatedWhen, StringFormat='Last Updated: {0:dd MMM yyyy HH:mm}'}" 
                               VerticalTextAlignment="Center" HorizontalTextAlignment="End" FontSize="Small" />
        <customControls:ImageButton x:Name="fab" 
                                Source="{markupExtensions:PlatformImage SourceImage='IconFAB'}"
                                Command="{Binding AddCommand}"
                                AbsoluteLayout.LayoutFlags="PositionProportional"
                                AbsoluteLayout.LayoutBounds="0.95,0.975,-1,-1"
                                Margin="10" />
    </StackLayout>
</ContentPage>

如果我使用 StackLayout,WebView 的大小和滚动正确,但是 FAB 占据屏幕底部的全宽条,并且文本不会出现在其后面 - WebView 停止在其上方。

我在过去的一个半小时里尝试了所有我能想到的嵌套布局组合来解决这个问题,但就是无法正确解决这个问题 - 那里有一些布局天才请告诉我如何解决这个问题.

谢谢

【问题讨论】:

    标签: xaml xamarin webview xamarin.forms floating-action-button


    【解决方案1】:

    使用Grid,不要表示行或列。

    类似这样的:

    <Grid Padding="5,5,5,5"
          VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand">
        <WebView x:Name="webViewDocument"
                 VerticalOptions="FillAndExpand"
                 HorizontalOptions="FillAndExpand" />
        <Label Text="{Binding UpdatedWhen, StringFormat='Last Updated: {0:dd MMM yyyy HH:mm}'}"
               VerticalOptions="End"
               HorizontalOptions="Center"
               HorizontalTextAlignment="End"
               FontSize="Small" />
        <customControls:ImageButton x:Name="fab"
                                    Source="{markupExtensions:PlatformImage SourceImage='IconFAB'}"
                                    Command="{Binding AddCommand}"
                                    VerticalOptions="End"
                                    HorizontalOptions="End"
                                    Margin="10" />
    </Grid>
    

    这应该适合你。

    【讨论】:

    • 谢谢。 Aaaurgh,如此接近,我可以品尝到它!文本被正确包装,FAB 在 webview 上正确呈现......但 webview 文本不滚动。它仍然比我以前更接近......
    • @Mike 它不会滚动,因为在输入解决方案时出错。我刚刚更新了我的答案,现在应该可以工作了。在简历中,您使用垂直和水平选项,但不是高度/宽度
    • 感谢您的帮助,伙计。它仍然不会滚动。奇怪的是,当表单出现时,我可以看到滚动条短暂出现在右上角,这表明它知道文档的长度大于屏幕,它只是不会响应上下滑动。澄清一下 - 这是在一个 Android/iOS 解决方案的共享项目中,我正试图让它在 Android 中工作。
    • 擦掉,是标签阻止了它,因为我错过了水平和垂直选项。在我的书友中,你是一个“善良的布局天才”。
    猜你喜欢
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多