Ich versuche, die Höhe eines Webview zu bekommen, sobald es gerendert wurde. Es gibt immer null zurück, ich habe versucht getHeight
, getMeasuredHeight
, getContentHeight
und es gibt immer null zurück.Android Höhe von Webview Inhalt einmal gerendert
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/instructions"
android:background="@color/transparent_black" >
<WebView
android:id="@+id/top_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Aktivität
public class TestActivity extends MenuActivity {
private final static String TAG = "HearingTest";
private String urlTopContent;
private WebView topContent;
private boolean mMoreInfoTop = true;
private int mYdelta = 0;
private int mBottomOffset = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.right_hearing_test);
String topHtml = this.getString(R.string.top_content);
//String bottomHtml = this.getString(R.string.bottom_content);
urlTopContent = "file:///android_asset/html/" + topHtml;
WebViewSettings();
LoadWebPage(urlTopContent);
}
public void WebViewSettings(){
topContent = (WebView) findViewById(R.id.top_content);
topContent.getSettings().setJavaScriptEnabled(true);
topContent.getSettings().setBuiltInZoomControls(true);
topContent.getSettings().setSupportZoom(true);
topContent.getSettings().setLoadWithOverviewMode(true);
topContent.setBackgroundColor(0);
topContent.canGoBack();
int topHeight = topContent.getContentHeight();
Log.d("Top Height", "Height: " + topHeight);
topContent.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals(urlTopContent)) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
View webViewHeight = (View) findViewById(R.id.top_content);
int height = webViewHeight.getHeight();
Log.d("Top Content","Top Content Height:" + height);
}
});
}
public void LoadWebPage(String url){
try {
topContent.loadUrl(url);
Log.d("Loading Web Page", "URL" + url + "connected");
}
catch (Exception e) {
Log.d("Loading Web Page", "URL: " + url + " couldn't connect.");
}
}
}
Ich weiß nicht einmal, ob es möglich ist, die Höhe der Web-Ansicht zu erhalten, nachdem es gemacht hat, aber ich don‘ Warum nicht? Wenn jemand eine Lösung hat, würde es sehr geschätzt werden.
arbeitete wie ein Charme, vielen Dank auf diese seit Ewigkeiten fest. – Paddy1990
wo, nach onloadPageFinish? – NovusMobile
Ich bekomme einen falschen Wert .. Testen Sie www.google.com Geben Sie 714px – NovusMobile