'How to get the full height of in android WebView?
I have a RelativeLayout with WebView. I am loading some generated html text into that WebView. After loading the data WebView height exceeding the screen. Now I need the height of the entire WebView. Till now I tried WebView#getHeight(), WebView#getBottom() but I'm getting the height of visible content.
Solution 1:[1]
Wrap your WebView within a ScrollView and webView.getHeight() will return the height of the actual WebView content. Make sure your WebView's height attribute is set to wrap_content.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</WebView>
</ScrollView>
Solution 2:[2]
public class CustomWebView extends WebView{
public CustomWebView(Context context) {
super(context);
}
int ContentHeight = 0;
public int getContentHeight(){
if(ContentHeight==0)
ContentHeight = computeVerticalScrollRange();
return ContentHeight;
}
}
Webview has protected method computeVerticalScrollRange(). you can access this method by creating custom one.
((CustomWebView) webView).getContentHeight())
Solution 3:[3]
My Answer:-
I think you have to remove padding properties from your layout.xml file
(i.e) Remove the following content from your XML file and try it.
android:paddingBottom
android:paddingLeft
android:paddingRight
android:paddingTop
Hope it helps!!
Solution 4:[4]
kotlin: myWebView.contentHeight
Solution 5:[5]
In your Java class add the getWindow()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_webview);
}
Solution 6:[6]
private int getScale(){
Display display = ((WindowManager)
getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
Double val = new Double(width)/new Double(PIC_WIDTH);
val = val * 100d;
return val.intValue();
}
check this link! for more information
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ivan |
| Solution 2 | JaKang Chen |
| Solution 3 | Chris Stillwell |
| Solution 4 | Leonid Ivankin |
| Solution 5 | Srinivas Keerthiprakasam |
| Solution 6 | Chris Stillwell |

