本文介绍了Web视图缩放控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

htmlp = URLEncoder.encode(desc,"utf-8").replaceAll("\\+"," ");
            WebView wv=(WebView)findViewById(R.id.webView1);
            wv.setInitialScale(70);
            wv.getSettings().setJavaScriptEnabled(true);
            wv.getSettings().setPluginsEnabled(true);
            wv.getSettings().setSupportZoom(true);
            wv.getSettings().setLoadWithOverviewMode(true);
            wv.getSettings().setBuiltInZoomControls(true);
            wv.loadData(htmlp,"text/html", "utf-8");

在htmlp包含HTML内容(标签)。现在我必须启用缩放控制,但是使用上述code这是行不通的。是什么,我在WebView中的XML部分启用。

In htmlp contains HTML content(tags). Now I have to enable zooming control, but using above code it is not working. Is anything I have to enable in xml part of the webview.

在此先感谢

推荐答案

这工作在我case.Try它为你的情况好结果..
在manifest文件..

This works good in my case.Try it for your case..
In manifest file..

<uses-permission android:name="android.permission.INTERNET">
</uses-permission>

webview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  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/webView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  />
</LinearLayout>

在活动..

public class Main extends Activity {
  private WebView myWebView;
  private static final FrameLayout.LayoutParams ZOOM_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,Gravity.BOTTOM);

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.webview);
    this.myWebView = (WebView) this.findViewById(R.id.webView);

    FrameLayout mContentView = (FrameLayout) getWindow().
    getDecorView().findViewById(android.R.id.content);
    final View zoom = this.myWebView.getZoomControls();
    mContentView.addView(zoom, ZOOM_PARAMS);
    zoom.setVisibility(View.GONE);

    this.myWebView.loadUrl("http://www.facebook.com");
  }
}

这篇关于Web视图缩放控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:58