Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 防止菜单项动画重叠?_Android_Android Webview_Android Animation - Fatal编程技术网

Android 防止菜单项动画重叠?

Android 防止菜单项动画重叠?,android,android-webview,android-animation,Android,Android Webview,Android Animation,因此,每当webview加载时以及每当活动开始时,我都会尝试设置刷新menuitem的动画。我还试图在不必要时隐藏转发菜单项。下面的代码工作得很好,除了在加载webview时进行回击,或者在尝试一次执行多个任务时(在大量历史记录中单击“上一步”)之外。每当发生这种情况时,“刷新”菜单项会自动复制、设置动画和重叠。前进菜单项也会出现这种情况。它往往与动画刷新图标重叠。有没有办法阻止这种事情发生?下面的代码完全是我的代码,除了任何不相关的代码都被删除了。有人能帮我克服这个错误吗 public cla

因此,每当
webview
加载时以及每当活动开始时,我都会尝试设置刷新
menuitem
的动画。我还试图在不必要时隐藏转发
菜单项。下面的代码工作得很好,除了在加载webview时进行回击,或者在尝试一次执行多个任务时(在大量历史记录中单击“上一步”)之外。每当发生这种情况时,“刷新”菜单项会自动复制、设置动画和重叠。前进
菜单项也会出现这种情况。它往往与动画刷新图标重叠。有没有办法阻止这种事情发生?下面的代码完全是我的代码,除了任何不相关的代码都被删除了。有人能帮我克服这个错误吗

public class TideWeb extends Activity {
    private static WebView webView;
    String name = null;
    MenuItem refresh, forward;
    ActionBar ab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent launchingIntent = getIntent();
        name = launchingIntent.getType().toString();
        setContentView(R.layout.webview);
        webView = (WebView) findViewById(R.id.WebView);
        webView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView webview, String url) {
                    if (refresh != null && refresh.getActionView() == null) {
                        StartAnimation();
                    }
                    ab.setSubtitle("Loading...");
                    webView.loadUrl(url);

                return true;

            }
        });
        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                setSupportProgress(progress * 100);
                if (progress == 100) {
                    view.clearCache(true);
                    StopAnimation();
                    ab.setSubtitle(name);
                }
            }
        });
        String url = launchingIntent.getData().toString();

        webView.loadUrl(url);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.tideweb, menu);
        forward = menu.findItem(R.id.forward_menu);
        if (webView.isFocused() && webView.canGoForward()) {
            forward.setVisible(true);
        } else {
            forward.setVisible(false);
        }
        ab.setSubtitle("Loading...");
        refresh = menu.findItem(R.id.refresh_menu);
        if (refresh != null && refresh.getActionView() == null) {
            StartAnimation();
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.forward_menu:
            webView.goForward();
            invalidateOptionsMenu();
            break;
        case R.id.refresh_menu:
            webView.reload();
            invalidateOptionsMenu();
            break;
        case android.R.id.home:
            Intent intent = new Intent(this, Main.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            return true;
        }
        return true;
    }

    public void onBackPressed() {
        if (webView.isFocused() && webView.canGoBack()) {
            webView.goBack();
            invalidateOptionsMenu();
        } else {
            super.onBackPressed();
            finish();
        }
    }

    private void StartAnimation() {
    if (refresh != null && refresh.getActionView() == null) {
            final LayoutInflater inflater = (LayoutInflater) getApplication()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final RelativeLayout ivRefresh = (RelativeLayout) inflater.inflate(
                R.layout.refresh_view, null);

            final Animation rotation = AnimationUtils.loadAnimation(
                getApplication(), R.anim.rotate);
            ivRefresh.startAnimation(rotation);
            refresh.setActionView(ivRefresh);
        }
    }

    private void StopAnimation() {
        if (refresh != null && refresh.getActionView() != null) {
            refresh.getActionView().clearAnimation();
            refresh.setActionView(null);
        }
    }
}
加载,然后返回:

加载,然后来回加载:

我没有找到解决方法,但我没有使用图像并设置动画,而是将actionview设置为progressbar。重叠不再发生,所以我想现在已经修复了。

接受你的答案。你会得到一枚徽章(我想)@尼古拉·德斯波托斯基:谢谢你的建议!但我真的不喜欢徽章。我只是想帮助别人,如果他们遇到这个问题。