更改页面和显示模式时Android上的Webview显示问题纵向->横向

问题描述

当我尝试以横向模式 ( https://web-labosims.org/animations/App_refraction_reflexion/App_refraction&reflexion.html ) 在 webView显示我的一个网页时,它可以在 Android 上正常工作。

Screenshots

但是当它不是第一页并且我在页面之间更改方向时,它在 Android 上不再正常工作(显示问题)...

MainPage.xaml.cs

    public partial class MainPage : ContentPage
    {
        private List<Anim> lesAnimations;
        public MainPage()
        {
            InitializeComponent();

            String animsJson = "[{\"Nom\":\"Réfraction et réfexion\",\"url\":\"https://web-labosims.org/animations/App_refraction_reflexion/App_refraction&reflexion.html\",\"imageUrl\":\"App_refraction.png\"},{\"Nom\":\"Synthèse soustractive\",\"url\":\"https://web-labosims.org/animations/App_lumiere3/App_lumiere3.html\",\"imageUrl\":\"App_soustractive.png\"}]";

            lesAnimations = JsonConvert.DeserializeObject<List<Anim>>(animsJson);

            maListView.ItemsSource = lesAnimations;

            maListView.ItemSelected += (sender,e) =>
            {
                if (maListView.SelectedItem != null)
                {
                    Anim item = maListView.SelectedItem as Anim;

                    GoAnimation(item.url);
                }
                maListView.SelectedItem = null;
            };

        }

        private async Task GoAnimation(String url)
        {
            await this.Navigation.PushAsync(new Animation(url));
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();
            DependencyService.Get<IOrientationHandler>().ForcePortrait();
        }

        protected override void Ondisappearing()
        {
            base.Ondisappearing();
            DependencyService.Get<IOrientationHandler>().ForceLandscape();
        }

    }

动画.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:LaboSims;assembly=LaboSims"
             x:Class="LaboSims.Animation">
    <ContentPage.Content>
            <WebView x:Name="maWebView"  
                     WidthRequest="1000"
                     HeightRequest="1000"
                     />
    </ContentPage.Content>
</ContentPage>

Animation.xaml.cs

public partial class Animation : ContentPage
    {
        public Animation(String url)
        {
            InitializeComponent();

            NavigationPage.SetHasNavigationBar(this,false);

            maWebView.source = url;
        }

    }

IOrientationHandler.cs

namespace LaboSims
{
    public interface IOrientationHandler
    {
        void ForceLandscape();
        void ForcePortrait();
    }
}

在安卓上

using Android.Content.PM;
using LaboSims.Droid;
using Plugin.CurrentActivity;

[assembly: Xamarin.Forms.Dependency(typeof(OrientationHandler))]
namespace LaboSims.Droid
{
    public class OrientationHandler : IOrientationHandler
    {
        public void ForceLandscape()
        {
            CrossCurrentActivity.Current.Activity.RequestedOrientation = Screenorientation.Landscape;
        }

        public void ForcePortrait()
        {
            CrossCurrentActivity.Current.Activity.RequestedOrientation = Screenorientation.Portrait;
        }
    }
}

Screenshots

我不明白我哪里出错了...

解决方法

我确信问题应该很简单,而且确实是一个简单的错误……我在网页上的元标记中犯了一个小错误。 我把它改成:

<meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1,maximum-scale=1">

而且一切正常