5

getScale () was deprecated in API level 17. so , how can i get the current scale of a webview. i tried to override the method onScaleChanged, but it won`t be called unless i change the scale...

Richard Guan
  • 137
  • 2
  • 7

2 Answers2

10

I know this question is a bit old, but this may help someone (like me), especially if someone wants to override WebView and add onTouch listener, to detect WebView's content end.

You can use:

getResources().getDisplayMetrics().density

instead of

webView.getScale()

which is deprecated.

It is the same value, that represents screen density, compared to mdpi value. So, it will be as follows:

  • ldpi: 0.75
  • mdpi: 1.0
  • hdpi: 1.5
  • xhdpi: 2.0
  • xxhdpi: 3.0
  • xxxhdpi: 4.0
Dimmy3
  • 926
  • 2
  • 13
  • 25
  • 1
    No, I get completely different values for webview.scale, webview.scaleY and resources.displayMetrics.density. – fattire Sep 21 '20 at 23:20
2

WebView.getScaleX() and WebView.getScaleY() might help, is this what you want?

I don't have enough reputation to comment on your questions, so I'll just give an answer. Hope this helps (:

chinglun
  • 637
  • 5
  • 18
  • 1
    Thank you for your answer. getScale returns 2. but getScaleX and getScaleY returns 1. I don`t know what that means.. – Richard Guan Nov 11 '13 at 02:38
  • Does both getScaleX() and getScaleY() return 1? It means the current view is 1.0x than the origin view, which means no scaling is implied. And I don't know why getScale() returns 2. Sorry for that. – chinglun Nov 11 '13 at 02:49
  • that`s all right. I think getScaleX/Y return the view scale not the webpage scale.. – Richard Guan Nov 11 '13 at 03:09
  • have you seen this post? http://stackoverflow.com/questions/10279613/why-does-getscaley-always-returns-1-0-android – chinglun Nov 11 '13 at 04:22