Reputation: 3192
My webview (initially invisible) gets url to load:
@Override
public void onCreate(Bundle savedInstanceState){
...
webView.loadUrl("some url");
...
}
Then, in onClickListener I change its visibility to visible and see nothing loaded. If I set visibility to visible and THEN load url, it works ok, but user should wait for some time while url is loading. I want to preload everything and show ALREADY LOADED webpage. How to do it? Webview loads something if only it is visible...
P.S. btw, I tried making the webview visible and setting translationY large enough the view to go below screen - still, it loads nothing unless I invoke setTranslationY(0); ... what to do?
P.P.S. I tried invoking webView.loadData - same effect.
Upvotes: 2
Views: 2586
Reputation: 419
try this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_web);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.co.uk");
mWebView.setWebViewClient(new HelloWebViewClient());
}
public void testing (View view){
mWebView.setVisibility(View.VISIBLE);
}
Button in screen_web.xml:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="testing"
android:text="Button" />
WebView in screen_web.xml:
<WebView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.32"
android:visibility="invisible" />
It works well for me.
Upvotes: 1