【问题标题】:Webview can't scrollWebview 无法滚动
【发布时间】:2016-10-23 14:45:01
【问题描述】:

我有这个 Xamarin 表单页面:

<?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:local="clr-namespace:TestApp1"
             x:Class="TestApp1.MainPage">
<ContentPage.Content>
  <StackLayout Orientation="Vertical">
    <WebView Source="http://www.google.de" HeightRequest="3000" WidthRequest="100"/>
  </StackLayout>
</ContentPage.Content>
</ContentPage>

当我打开我的应用程序时,在 google 提示符中输入任何内容时,我无法在结果页面上滚动。如何启用此功能?

当我在谷歌上搜索“xamarin webview 启用滚动”时,我只能找到有关禁用它的信息...

【问题讨论】:

  • 考虑到高度请求确实认为WebView高到不需要滚动?
  • 你在什么平台上测试?
  • 发现和stacklayout有关。如果我在 stacklayout 中没有 webview,它滚动得很好。但后来我问自己,我如何对齐表单上的任何其他控件,以使用户能够访问选项或类似的东西,同时仍然让 webview 占用其余空间。
  • 我在 Windows Phone 10 上测试
  • 在 Android 上它适用于堆栈布局。我可以尝试在 Windows phone 8 上进行测试。它适用于你的 phone 8 吗?您能否在此页面上提供您想要实现的图像?顺便提一句。在 Android 上设置宽度和高度请求似乎没有任何效果。我认为你应该使用 Horizo​​ntalOptions 和 VerticalOptions

标签: xamarin webview


【解决方案1】:

创建您自己的渲染器并覆盖此方法,如下所示:

public override bool DispatchTouchEvent(MotionEvent e)
{
    Parent.RequestDisallowInterceptTouchEvent(true);
    return base.DispatchTouchEvent(e);
}

Please find details in this link

【讨论】:

  • 在更新到 Android SDK 28 并同时更新 Xamarin.Forms 后,我的 WebViews 不再滚动,但这修复了它。
【解决方案2】:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ButtonRendererDemo.WebViewPage">

  <ContentPage.Content>
    <StackLayout Orientation="Vertical" Padding="10" Spacing="10">
      <Button Text="Press me" HorizontalOptions="CenterAndExpand" VerticalOptions="Center" BackgroundColor="Green"/>        
      <WebView Source="http://www.google.de" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
    </StackLayout>
  </ContentPage.Content>    
</ContentPage>

【讨论】:

    【解决方案3】:

    对我来说,问题出在 &lt;WebView/&gt; 内部,我设置了静态的 HeightRequest 和 WidthRequest - 因为文档说如果您使用 &lt;StackLayout&gt;,这些都是必需的 - 但事实并非如此

    删除这些并添加 VerticalOptions="FillAndExpand"Horizo​​ntalOptions="FillAndExpand" 为我解决了问题并允许我按预期滚动。

    <WebView VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Source="https://google.com/"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多