Xamarin WebView规模适合

时间:2016-12-15 00:56:54

标签: xamarin xamarin.forms

有没有办法在Xamarin中设置WebView,以便在默认情况下缩放其内容以适应屏幕,并且仍允许缩放放大/缩小?

我们将使用它来显示我们在线的文件。

2 个答案:

答案 0 :(得分:2)

我通过自定义渲染器解决了缩放适合页面和缩放的问题,如下所示

对于IOS

 public class CustomWebViewRenderer : WebViewRenderer
{
    protected override void OnElementChanged(VisualElementChangedEventArgs e)
    {
        base.OnElementChanged(e);

        var view = Element as CustomWebView;
        if (view == null || NativeView == null)
        {
            return;
        }
        this.ScalesPageToFit = true;
    }

}

对于Android

public class CustomWebViewRenderer : WebViewRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
    {
        base.OnElementChanged(e);

        if (Control != null)
        {
            Control.Settings.BuiltInZoomControls = true;
            Control.Settings.DisplayZoomControls = false;

            Control.Settings.LoadWithOverviewMode = true;
            Control.Settings.UseWideViewPort = true;
        }
    }
}

答案 1 :(得分:-1)

如果您正在使用看起来像这样的Xamarin.Forms

<?php
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Response;
use ReCaptcha\ReCaptcha;

class MyController extends Controller {

    private $salt_length = 10;

    private $resources;
    private $request;
    private $session;
    private $message;
    private $loggedin;

    /**
     * @Route("/My/home")
     */
    //
    // My home page
    //
    public function homeAction() {

       // bla bla

    }

    require 'utilities.php'; // <<==============

}
?>

这应填满页面,不会影响捏合和缩放。