【问题标题】:Android Webview Image Render to Center rather than top-left cornerAndroid Webview 图像渲染到中心而不是左上角
【发布时间】:2012-04-18 00:37:18
【问题描述】:

webview 中的图像渲染从我的图像的左上角开始,该图像比 webview 大,因此可以滚动。我想将图像居中而不是渲染到左上角...有什么办法吗?

【问题讨论】:

    标签: android webview


    【解决方案1】:

    您可以使用纯 CSS 并调用 myWebView.loadData,而不是调用 myWebView.loadUrl。

    只需确保对所有无关字符进行 URL 编码即可。 示例:

    myWebView.loadData("<html><head><style type='text/css'>body{margin:auto auto;text-align:center;} img{width:100%25;} </style></head><body><img src='www.mysite.com/myimg.jpeg'/></body></html>" ,"text/html",  "UTF-8");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-27
      • 2021-01-17
      • 2016-08-28
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      • 2011-06-30
      • 1970-01-01
      相关资源
      最近更新 更多