在 Android WebView 中适配网页 [英] Fit webpage in Android WebView

查看:50
本文介绍了在 Android WebView 中适配网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ASP.NET 中有一个网页,现在我正在使用 Xamarin 创建一个 Android 应用程序,用户可以通过它访问此网页.我正在使用 WebView.

I have a webpage in ASP.NET and now I am creating an Android application using Xamarin through which user can access this webpage. I am using WebView.

我面临的问题是网页的内容不适合 WebView,这可能是一个重复的问题,但我在以前的帖子中没有得到正确的答案.

Problem I am facing is that the content of webpage is not fitting in WebView, probably it seems a duplicate question but I did not got a proper answer in previous posts.

我的布局代码是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <WebView 
        android:id="@+id/webview1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</RelativeLayout>

MainActivity 代码是

namespace DsclQuery
{
    [Activity (Label = "DsclQuery", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar")]
    public class MainActivity : Activity
    {
        WebView webview;

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
            webview = FindViewById<WebView> (Resource.Id.webview1);
            webview.LoadUrl ("http://www.dsclsugar.com/QuerySecure");
            webview.SetWebViewClient (new dsclQueryWebViewClient());
            webview.Settings.JavaScriptEnabled = true;
            webview.Settings.UseWideViewPort = true;
            webview.Settings.BuiltInZoomControls = true;
        }
    }

我该怎么做?

推荐答案

试试这个代码:

webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("your url");

int scale = (int) (100 * webview.getScale());
webview.setInitialScale(scale);

webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setBuiltInZoomControls(true);

它的android原生代码,我想你能看懂!

Its android native code, I think you can understand !

希望有用.谢谢.

这篇关于在 Android WebView 中适配网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆