如何在Android屏幕上安装网页(webview)?

时间:2011-06-14 21:07:21

标签: android webview android-webview

  

可能重复:
  Android Webview - Webpage should fit the device screen

我想在android的webview中呈现一个网页。目前,我可以显示网页,但如何使其适合屏幕? 我提到: Android Webview - Webpage should fit the device screen 但没有在那里找到解决方案。

谢谢!

3 个答案:

答案 0 :(得分:29)

对我有用的唯一方法就是这样:

webView = (WebView) findViewById(R.id.noticiasWebView);
webView.setInitialScale(1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.loadUrl("http://www.resource.com.br/");

我正在使用Android 2.1,因为该公司提供的设备类型。但是我使用每个信息的一部分解决了我的问题。

答案 1 :(得分:8)

我的解决方案不同。 我制作了一个足够大的网页,然后它会缩小。在webview设置中,我提出以下内容:

WebView webview = new WebView(this);
//webview.setInitialScale(100); No need for this one
WebSettings settings = webview.getSettings();
settings.setBuiltInZoomControls(false);
settings.setUseWideViewPort(true);
settings.setJavaScriptEnabled(true);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setLoadsImagesAutomatically(true);
settings.setLightTouchEnabled(true);
settings.setDomStorageEnabled(true);
settings.setLoadWithOverviewMode(true);

请务必导入以下内容:import android.webkit.WebSettings.ZoomDensity;

答案 2 :(得分:4)

你的问题不是很明确,但如果我猜你的意思是webview没有扩展到整个屏幕?请发布您的代码以支持您的问题。

要将webview扩展到整个屏幕,请在活动布局xml中添加webview,并确保将layout_widthlayout_height设置为fill_parent。这是一个简单的例子:

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

赖安

相关问题