gpt4 book ai didi

c# - 如何在标签或图像下方添加 Webview,并同时为 IOS 和 Android 滚动所有元素?

转载 作者:行者123 更新时间:2023-11-30 17:26:40 25 4
gpt4 key购买 nike

我正在为 IOS 和 Android 开发 Xamarin.Forms 应用程序。我在 XAML 文件中的代码是这样的:

<StackLayout BackgroundColor="White" Padding="1" VerticalOptions="FillAndExpand">
<Image HeightRequest="150" Aspect="AspectFill" Source="{Binding Post.ImageUrl}" />
<Label Text="{Binding Post.Title}" VerticalOptions="FillAndExpand" FontFamily="{StaticResource BoldFont}" FontSize="20" />
<Label Text="{Binding Post.CreatedOn}" VerticalOptions="FillAndExpand" FontFamily="{StaticResource NormalFont}" FontSize="12" />
<WebView x:Name="WebViewer" HeightRequest="500" VerticalOptions="FillAndExpand" BackgroundColor="White">
<WebView.Source>
<HtmlWebViewSource Html="{Binding Post.Data.Content}" />
</WebView.Source>
</WebView>
<Label Text="Comments" FontSize="12" />
</StackLayout>

当我模拟应用程序时,只有 Webview Scrolls 和所有其他元素保持固定。 Stackoverflow 上还有另一个类似的问题,但该解决方案不起作用,也没有回答我针对 IOS 的问题,它仅针对 Android。

This image shows the webview scrolling, and it's siblings staying in place

我希望它们一起滚动,这样它就像一页一样。这应该是一个跨平台的解决方案,所以我只需要为 IOS 和 Android 编写一次代码。我怎样才能做到这一点?

最佳答案

你可以试试这样的东西

设计方面

 <?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="XamarinTest.View.WebViewDemo">
<ContentPage.Content>
<ScrollView>
<StackLayout BackgroundColor="White" Padding="1" VerticalOptions="FillAndExpand">
<Image HeightRequest="150" Aspect="AspectFill" Source="home" />
<Label Text="Header" FontSize="20" />
<Label Text="Subheader" FontSize="12" />
<WebView Source="http://www.google.com" x:Name="WebViewer" BackgroundColor="White">
</WebView>
<Label Text="Comments" FontSize="12" />
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>

编码方面

using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace XamarinTest.View
{
public partial class WebViewDemo : ContentPage
{
public WebViewDemo()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();

}

protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
WebViewer.HeightRequest = height;
WebViewer.WidthRequest = width;

}
}
}

关于c# - 如何在标签或图像下方添加 Webview,并同时为 IOS 和 Android 滚动所有元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56053700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com