【问题标题】:Android Webview specific content of the page to zoom by defaultAndroid Webview 特定页面内容默认缩放
【发布时间】:2019-04-18 08:54:10
【问题描述】:

我在第一次加载 URL 时在我的应用程序中使用 WebView,它应该默认显示要缩放的页面的特定内容。我尝试过使用缩放功能,但它不起作用。

【问题讨论】:

    标签: android android-layout layout kotlin


    【解决方案1】:

    要向页面显示特定内容(在放大或缩小状态),您可以使用setInitialScale() 设置比例

    class WebviewActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            setContentView(R.layout.webview_activity)
            val myWebView: WebView = findViewById(R.id.my_web_view)
            myWebView.loadUrl("https://www.example.com")
    
            // use a number greater than 100 to zoom in closer.
            // my emulator maxes out around 470 (after which higher numbers do not make a difference).
            myWebView.setInitialScale((100 * myWebView.scale).toInt())
    
            myWebView.settings.useWideViewPort = true // support a wide viewport
            myWebView.settings.loadWithOverviewMode = true // fits contents to the screen by width
        }
    }
    

    我从 WebSettings 添加了两个方法:useWideViewPort 允许 WebViews 支持宽视口,loadWithOverviewMode 允许将内容按宽度调整到屏幕上。

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多