如何使用Web视图中的机器人的过渡效果? [英] How can I use android transition effects in web view?

查看:98
本文介绍了如何使用Web视图中的机器人的过渡效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果任何人都可以帮我这个,我会很高兴的。我有一个使用的WebView的应用程序。 web视图加载一个网址,我已经使用了谷歌的教程,在此改变一切,我想与web视图打开也是其他环节。我创建 RES / 的animimation文件和 slide_right XML 键,到目前为止好。我所说的效果在我主要的Java活动,但它仅适用于第一页。我想的事情是在每一个网页链接中的WebView负载应用的效果。

您能帮我与我的code?

包com.ihome;

 进口android.app.Activity;

进口android.app.AlertDialog;
进口android.content.Context;
进口android.content.DialogInterface;
进口android.content.Intent;
进口android.net.ConnectivityManager;
进口android.net.NetworkInfo;
进口android.os.Bundle;
进口android.view.KeyEvent;
进口android.view.Menu;
进口android.view.MenuInflater;
进口android.view.MenuItem;
进口android.view.animation.Animation;
进口android.view.animation.AnimationUtils;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;



公共类IhomeActivity延伸活动{
    的WebView mWebView;
    私有类HelloWebViewClient扩展WebViewClient {
        @覆盖
        公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
            动画slideRightAnimation = AnimationUtils.loadAnimation(getBaseContext(),R.anim.slide_right);
            mWebView.startAnimation(slideRightAnimation);
            view.loadUrl(URL);
            返回true;
        }
    }


@覆盖
    公共布尔的onkeydown(INT键code,KeyEvent的事件){
        如果((钥匙code == KeyEvent.KEY code_BACK)及和放大器; mWebView.canGoBack()){
            动画slideLeftAnimation = AnimationUtils.loadAnimation(getBaseContext(),R.anim.slide_left);
            mWebView.startAnimation(slideLeftAnimation);
            mWebView.goBack();
            返回true;
        }
        返回super.onKeyDown(键code,事件);
    }

/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    mWebView =(web视图)findViewById(R.id.webview);
    mWebView.setVerticalScrollBarEnabled(假);
    mWebView.setHorizo​​ntalScrollBarEnabled(假);
    mWebView.getSettings()setJavaScriptEnabled(真)。
    mWebView.loadUrl(http://www.google.com/);
    mWebView.setWebViewClient(新HelloWebViewClient());
 

解决方案

这是最好的,我可以做本机API,似乎时机是不完全正确,因为网页和动画的加载是异步的..编辑:更新了,这个人是略好。 EDIT2:这是我最好的尝试,到目前为止,它允许用户认识到页面加载..获得半流畅的动画效果的唯一方法是让该页面以preLOAD,而用户不看看吧。

 包com.adeptdev.animwebview;

进口android.app.Activity;
进口android.app.ProgressDialog;
进口android.os.Bundle;
进口android.view.KeyEvent;
进口android.view.View;
进口android.view.animation.Animation;
进口android.view.animation.AnimationUtils;
进口android.webkit.WebView;
进口android.webkit.WebViewClient;

公共类HelloWebViewActivity延伸活动{
    ProgressDialog mProgressDialog;


    私有类HelloWebViewClient扩展WebViewClient {
        @覆盖
        公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
            view.setVisibility(View.GONE);
            mProgressDialog.setTitle(加载);
            mProgressDialog.show();
            mProgressDialog.setMessage(加载+网址);
            返回false;
        }

        @覆盖
        公共无效onPageFinished(web视图查看,字符串URL){
            mProgressDialog.dismiss();
            动画(视图);
            view.setVisibility(View.VISIBLE);
            super.onPageFinished(查看,网址);
        }
    }

    私人无效动画(最终的WebView视图){
        动画动画= AnimationUtils.loadAnimation(getBaseContext()
                android.R.anim.slide_in_left);
        view.startAnimation(动画);
    }

    @覆盖
    公共布尔的onkeydown(INT键code,KeyEvent的事件){
        的WebView视图=(web视图)findViewById(R.id.webview);
        如果((钥匙code == KeyEvent.KEY code_BACK)及和放大器; view.canGoBack()){
            view.goBack();
            返回true;
        }
        返回super.onKeyDown(键code,事件);
    }

    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        mProgressDialog =新ProgressDialog(本);
        的WebView web视图=(web视图)findViewById(R.id.webview);
        webView.setVerticalScrollBarEnabled(假);
        webView.setHorizo​​ntalScrollBarEnabled(假);
        webView.getSettings()setJavaScriptEnabled(真)。
        webView.loadUrl(http://www.google.com/);
        webView.setWebViewClient(新HelloWebViewClient());
    }
}
 

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 other links that I want to open with webview also. I have create an animimation file in res/ and a slide_right xml and so far so good. I call the effect in my main java activity but it only applies to the first page. The thing that I want is the effect to apply in every page that links loads in webview.

Can you help my with my code?

package com.ihome;

import android.app.Activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebView;
import android.webkit.WebViewClient;



public class IhomeActivity extends Activity {
    WebView mWebView;
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Animation slideRightAnimation = AnimationUtils.loadAnimation(getBaseContext (), R.anim.slide_right);
            mWebView.startAnimation(slideRightAnimation);
            view.loadUrl(url);
            return true;
        }
    }


@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            Animation slideLeftAnimation = AnimationUtils.loadAnimation(getBaseContext (), R.anim.slide_left);
            mWebView.startAnimation(slideLeftAnimation);
            mWebView.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);
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl("http://www.google.com/");
    mWebView.setWebViewClient(new HelloWebViewClient());

解决方案

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());
    }
}

这篇关于如何使用Web视图中的机器人的过渡效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆