问题
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