Fit webpage in Android WebView

南楼画角 提交于 2019-12-13 05:52:24

问题


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.

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.

My layout code is :

<?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>

and MainActivity code is

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;
        }
    }

How can I do this ?


回答1:


Try This code:

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);

Its android native code, I think you can understand !

I hope it will useful. Thank you.



来源:https://stackoverflow.com/questions/22928732/fit-webpage-in-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!