动画不适用于InterstitialAd

时间:2019-02-02 21:33:28

标签: javascript java android interstitial

因此,我一直想构建游戏/应用程序,并在几年前学习过xml,7年级自学,多年以来失去了野心,而生活却并非如此。 2周前,我开始自学Java,并制作了一个简单的应用程序来旋转瓶子。我已经解决了大多数夸克问题,但我坚持在这儿做错了什么。 该应用程序完美运行,无需安装计数器即可弹出插页式广告,但是一旦我从“按钮旋转=(按钮)”插入“计数器= 1;}其他{...” 瓶子旋转的动画停止。我一直在网上浏览并尝试各种可以想到的事情,现在已经两天了,这让我发疯。任何帮助将不胜感激 预先感谢。

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

        }

1 个答案:

答案 0 :(得分:0)

我发现动画脚本中有一个小故障,我将上面的代码重写为所有工作正常,现在也许有人会发现这对点击计数器很有用。

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


}
}