How can I use android transition effects in web view?

后端 未结 1 1750
遇见更好的自我
遇见更好的自我 2020-12-13 05:17

If anyone can help me with this I will be very happy. I have an application that uses webview. The webview loads a url and I have used the Google tutorial to overide all the

相关标签:
1条回答
  • 2020-12-13 05:53

    This is the best I could do with the native apis, it seems the timing isn't quite right because the loading of the page and animation are asynchronous.. EDIT: updated, this one is marginally better. EDIT2: This is my best attempt so far, and it allows the user to realize that the page is loading.. The only way to get a semi-smooth animation is to allow the page to preload, while the user does not see it.

    package com.adeptdev.animwebview;
    
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    
    public class HelloWebViewActivity extends Activity {
        ProgressDialog mProgressDialog;
    
    
        private class HelloWebViewClient extends WebViewClient {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.setVisibility(View.GONE);
                mProgressDialog.setTitle("Loading");
                mProgressDialog.show();
                mProgressDialog.setMessage("Loading " + url);
                return false;
            }
    
            @Override
            public void onPageFinished(WebView view, String url) {
                mProgressDialog.dismiss();
                animate(view);
                view.setVisibility(View.VISIBLE);
                super.onPageFinished(view, url);
            }
        }
    
        private void animate(final WebView view) {
            Animation anim = AnimationUtils.loadAnimation(getBaseContext(),
                    android.R.anim.slide_in_left);
            view.startAnimation(anim);
        }
    
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            WebView view = (WebView) findViewById(R.id.webview);
            if ((keyCode == KeyEvent.KEYCODE_BACK) && view.canGoBack()) {
                view.goBack();
                return true;
            }
            return super.onKeyDown(keyCode, event);
        }
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mProgressDialog = new ProgressDialog(this);
            WebView webView = (WebView) findViewById(R.id.webview);
            webView.setVerticalScrollBarEnabled(false);
            webView.setHorizontalScrollBarEnabled(false);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.loadUrl("http://www.google.com/");
            webView.setWebViewClient(new HelloWebViewClient());
        }
    }
    
    0 讨论(0)
提交回复
热议问题