Web View Zooming Control

。_饼干妹妹 提交于 2019-12-24 20:19:36

问题


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

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.

Thanks in advance


回答1:


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>

In activity..

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



回答2:


   wv.getSettings().setBuiltInZoomControls(false);

change to false




回答3:


At last I have solved this problem. The problem was in the design section. Just changed the layout param to this:

WebView
         android:layout_width="match_parent"
         android:layout_height="match_parent"


来源:https://stackoverflow.com/questions/14563837/web-view-zooming-control

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