In an Activity with many components, I have a RelativeLayout that has a WebView (it shows plain text that I don't know its size).
This is the xml code:
<RelativeLayout android:id="@+id/descripcionRelative" android:layout_below="@+id/descripcion_bold" android:layout_width="match_parent" android:layout_height="125dip" android:background="@drawable/my_border">
<WebView android:id="@+id/webViewDescripcion" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</RelativeLayout>
The android: layout_height of RelativeLayout attribute is 125dip, because if the text is too large, I want to delimit 125dip. If the text is large, I will see the text with a scroll. Fine!
But ... if the text is short, I see a lot of necessary space.
One solution is to change android: layout_height RelativeLayout to wrap_content. If the text is short, the component will have exact pixels, but if the text is too large, I cannot distinguish it.
BIG PROBLEM: I cannot calculate the height of the WebView. If I do: descripcion_web.getHeight (), it returns 0.
If I call this method here, it does not return the well number:
descripcion_web.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView webView, String url) {
super.onPageFinished(webView, url);
RelativeLayout marco = (RelativeLayout)findViewById(R.id.descripcionRelative);
System.out.println("Height webView: "+webView.getHeight());
System.out.println("Height relative: "+marco.getHeight());
}
});
I am trying to call a method in onResume (), but it does not work.
Another attempt to solve the problem is to set android: layout_height for match_parent and use the View setMaximumHeight () method, but it does not exist. However, there is setMinimumHeight () ...
How can i solve this? Thank you very much!