【问题标题】:Animation not working with InterstitialAd动画不适用于 InterstitialAd
【发布时间】:2019-02-02 21:33:28
【问题描述】:

所以我一直想构建游戏/应用程序,并在几年前学习了一些 xml,7 年级自学,多年来有点失去了野心,生活什么都不是。 2 周前,我开始自学 Java,并制作了一个简单的应用程序。我已经计算出了大部分夸克,但我坚持这个我在这里做错了什么。 该应用程序在没有安装计数器来弹出插页式广告的情况下完美运行,但是一旦我从“Button spin =(Button)”插入到“counter =1;}else {...” 瓶子旋转的动画停止。我一直在网上浏览并尝试我能想到的不同的东西 2 天,这让我发疯了。任何帮助将不胜感激 提前致谢。

        Button spin =(Button) findViewById(R.id.button);
        ((Button) spin).setOnClickListener(new View.OnClickListener(){
            public void onClick(View view) {

                if (counter == 4) {
                    Log.i("log-", "INTERSTITIAL is loaded!");
                    if (mInterstitialAd.isLoaded()) {
                        mInterstitialAd.show();
                    }
                    counter = 1;
                }
                else {
                    counter++;
                }
            }
        });
    }



    public void spin(View v) {
            float newDirection = random.nextInt(3600);
            float pivoitX = imageView.getWidth() / 2;
            float pivoitY = imageView.getHeight() / 2;
            if (Math.abs(lastDirection - newDirection) < 360) {
                newDirection = lastDirection + newDirection + 360;
            }

            Animation rotate = new RotateAnimation(lastDirection, newDirection, pivoitX, pivoitY);

            rotate.setDuration(2000);
            rotate.setFillAfter(true);
            rotate.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    button.setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    button.setEnabled(true);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }


            });
            lastDirection = newDirection;
            imageView.startAnimation(rotate);

        }

【问题讨论】:

    标签: javascript java android interstitial


    【解决方案1】:

    我发现我的动画脚本有问题,我重写了上面的代码,现在一切正常,也许有人会发现这对点击计数器很有用。

    int counter = 0;
    
    public void spin(View v) {
    
    
        if (counter == 4) {
            Log.i("log-", "INTERSTITIAL is loaded!");
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            }
            counter = 1;
        }
        else {
            counter++;
    
            float newDirection = random.nextInt(3600);
            float pivoitX = imageView.getWidth() / 2;
            float pivoitY = imageView.getHeight() / 2;
            if (Math.abs(lastDirection - newDirection) < 360) {
                newDirection = lastDirection + newDirection + 360;
            }
            Animation rotate = new RotateAnimation(lastDirection, newDirection, pivoitX, pivoitY);
    
            rotate.setDuration(2000);
            rotate.setFillAfter(true);
            rotate.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    button.setEnabled(false);
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
                    button.setEnabled(true);
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
    
                }
            });
            lastDirection = newDirection;
            imageView.startAnimation(rotate);
        }
    
    
    }
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 2016-02-22
      • 2017-02-22
      • 2014-03-08
      • 2023-04-01
      • 2016-02-22
      相关资源
      最近更新 更多