[英]Webview display problem on Android when changing page and display mode (Portrait -> Landscape)
when I try to display in a webView
one of my web page in Landscape mode ( https://web-labosims.org/animations/App_refraction_reflexion/App_refraction&reflexion.html ) it works correctly on Android. when I try to display in a webView
one of my web page in Landscape mode ( https://web-labosims.org/animations/App_refraction_reflexion/App_refraction&reflexion.html ) it works correctly on Android.
But when it's not the first page and I change orientation between pages it doesn't work properly anymore on Android (display problem)...但是当它不是第一页并且我在页面之间更改方向时,它在 Android 上不再正常工作(显示问题)......
MainPage.xaml.cs主页.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();
}
}
Animation.xaml Animation.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 Animation.xaml.cs
public partial class Animation : ContentPage
{
public Animation(String url)
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
maWebView.Source = url;
}
}
IOrientationHandler.cs IOOrientationHandler.cs
namespace LaboSims
{
public interface IOrientationHandler
{
void ForceLandscape();
void ForcePortrait();
}
}
And on Android在 Android 上
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;
}
}
}
I don't understand where I make an error...我不明白我在哪里犯了错误......
I was sure that the problem should be simple and indeed it is a simple mistake... I had made a small mistake in my meta tag on my web page.我确信问题应该很简单,而且确实是一个简单的错误……我在 web 页面上的元标记中犯了一个小错误。 I changed it to:我将其更改为:
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
And everything is working properly一切正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.