发生另一次转换时的转换会导致错误

时间:2018-01-03 14:00:55

标签: java android transitions

我为乒乓球开发了一个得分计数器应用程序。 在其中,我已经为"服务变更" imgView。 但是,当快速按下分数按钮时,我会遇到问题,导致应用程序崩溃 ScoreActivity.java

    public class ScoreActivity extends AppCompatActivity {

    Button point1,point2;
    int points1=0,points2=0;
    ImageView serve;
    ViewGroup trans;
    TransitionSet set;
    TextView score1,score2,duce,adv1,adv2,p1,p2;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_score);

        initComponents();

        Fade fade = new Fade();
        Slide slideR = new Slide(Gravity.END);
        final Fade fadeout = new Fade(Fade.OUT);
        set = new TransitionSet()
                .addTransition(fade)
                .addTransition(slideR);

        set.addListener(new Transition.TransitionListener() {
            int n =0;
            @Override
            public void onTransitionStart(Transition transition) {
                n = 1;
            }

            @Override
            public void onTransitionEnd(Transition transition) {

                    fadeout.setStartDelay(500);
                    TransitionManager.beginDelayedTransition(trans,fadeout);
                    serve.setVisibility(View.GONE);

            }

            @Override
            public void onTransitionCancel(Transition transition) {

            }

            @Override
            public void onTransitionPause(Transition transition) {

            }

            @Override
            public void onTransitionResume(Transition transition) {

            }
        });

        makeAllGone();

        score1.setText("00");
        score2.setText("00");


        point1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                score1.setText(scoreIncrement(points1));
                points1++;

                if(isServiceChange()){
                    TransitionManager.beginDelayedTransition(trans,set);
                    serve.setVisibility(View.VISIBLE);
                    }


                viewDuceAdv();



        }});

        point2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                score2.setText(scoreIncrement(points2));
                points2++;


                if (isServiceChange()) {
                    TransitionManager.beginDelayedTransition(trans, set);
                    serve.setVisibility(View.VISIBLE);
                }
                viewDuceAdv();
            }});




}

    boolean isServiceChange(){
        int a= isDuceOrAdv();
        if(a==0){
        if((points1+points2)%2 == 0 && (points1 != 0 | points2 != 0))return true;}
        if(a>0){
            return true;
        }
        return false;
    }

    String scoreIncrement(int points){
        points++;
        if (points >= 10)return Integer.toString(points);

        return "0"+Integer.toString(points);
    }

    void makeAllGone(){
        serve.setVisibility(View.GONE );
        p1.setVisibility(View.GONE );
        p2.setVisibility(View.GONE );
        duce.setVisibility(View.GONE );
        adv1.setVisibility(View.GONE );
        adv2.setVisibility(View.GONE );
    }

    int isDuceOrAdv() {
        if (points1 >= 10 && points1 == points2) return 1; //  1 : DUCE
        if (points1 >9 && points2>9 ){if(points1> points2) return 2;      //  2 : ADVANTAGE player1
                                        if(points2>points1) return 3;}      // 3 : ADVANTAGE player2

        return 0; // 0 : Normal Points
    }

    void viewDuceAdv(){int DoA = isDuceOrAdv();
        switch(DoA){
            case 1 : duce.setVisibility(View.VISIBLE);
                adv1.setVisibility(View.INVISIBLE);
                adv2.setVisibility(View.INVISIBLE);
                break;
            case 2 : duce.setVisibility(View.INVISIBLE);
                adv1.setVisibility(View.VISIBLE);
                adv2.setVisibility(View.INVISIBLE);break;

            case 3 : duce.setVisibility(View.INVISIBLE);
                adv1.setVisibility(View.INVISIBLE);
                adv2.setVisibility(View.VISIBLE);break;
        }}

        void initComponents(){
            score1 = (TextView) findViewById(R.id.score1_tv);
            score2 = (TextView) findViewById(R.id.score2_tv);

            duce = (TextView) findViewById(R.id.duce);

            adv1 = (TextView) findViewById(R.id.adv1);
            adv2 = (TextView) findViewById(R.id.adv2);

            p1 = (TextView) findViewById(R.id.player1);
            p2 = (TextView) findViewById(R.id.player2);

            point1 = (Button) findViewById(R.id.point1);
            point2 = (Button) findViewById(R.id.point2);


            serve = (ImageView)findViewById(R.id.desc_imgView);

            trans = (ViewGroup)findViewById(R.id.trans);
        }

}

我无法弄清楚它崩溃的原因。 我正在使用" com.andkulikov:transitionseverywhere:1.7.8"动画库所以请帮我解决这个问题

  

01-03 19:27:02.429 2165-2165 / falsecreations.scoreboard E / dalvikvm:   找不到类' android.graphics.drawable.RippleDrawable',   从方法中引用   android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering   01-03 19:27:14.659 2165-2165 / falsecreations.scoreboard   E / AndroidRuntime:致命异常:主要                                                                            java.util.ConcurrentModificationException                                                                                at java.util.ArrayList $ ArrayListIterator.next(ArrayList.java:569)                                                                                在   com.transitionseverywhere.TransitionManager.sceneChangeSetup(TransitionManager.java:328)                                                                                在   com.transitionseverywhere.TransitionManager.beginDelayedTransition(TransitionManager.java:434)                                                                                在   falsecreations.scoreboard.ScoreActivity $ 3.onClick(ScoreActivity.java:108)                                                                                在android.view.View.performClick(View.java:3528)                                                                                在android.view.View $ PerformClick.run(View.java:14235)                                                                                在android.os.Handler.handleCallback(Handler.java:605)                                                                                在android.os.Handler.dispatchMessage(Handler.java:92)                                                                                在android.os.Looper.loop(Looper.java:137)                                                                                在android.app.ActivityThread.main(ActivityThread.java:4424)                                                                                at java.lang.reflect.Method.invokeNative(Native Method)                                                                                在java.lang.reflect.Method.invoke(Method.java:511)                                                                                在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:817)                                                                                在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)                                                                                at dalvik.system.NativeStart.main(Native Method)01-03 19:27:18.169   379-422 /? E / InputDispatcher:channel' 418eccb0   falsecreations.scoreboard / falsecreations.scoreboard.MainActivity   (服务器)' 〜频道无法恢复,将被处理掉!

0 个答案:

没有答案