mercredi 15 juin 2016

Randomly move ImageButton in a layout every 500ms

i have an image button and i want to move it randomly, i have no idea how to do that, i also tried other questions but was not able to understand, i want my image button to move randomly on screen and it should not move out,it should first be compatible with every device.

I also tried it by making buttons in a gridlayout and then individually making them visible and invisible for 1000ms,but it is not the efficient way... any other way to do so?

public void display(int x){
        String q=score.toString();
       s.setText(q);
            switch (x) {
                case 1: {
                    new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        b1.setVisibility(View.VISIBLE);
                        b1.setEnabled(true);
                        b1.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                score++;

                            }
                        });

                    }
                }, 1000);


                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {

                        disable();
                    int x=random();
                    display(x);
                    }
                }, 2000);



            } 




Aucun commentaire:

Enregistrer un commentaire