View appearance/disappearance is fine on some device, not on others

41 views Asked by At

I am having a really hard time trying to solve this problem : I programmed an app that allows user to get rid of some colored squares on the screen. In my class coloredSquare, I have a method like this :

public void appearance(){
    setLayoutParams(new RelativeLayout.LayoutParams(side/ 10, side/ 10));

    final int[] count = {1};
    final Runnable run = new Runnable() {
        @Override
        public void run() {
            setLayoutParams(new RelativeLayout.LayoutParams(count[0] * side/ 50, count[0] * side/ 50));//View grows of 1/50 of its final size
            if (count[0] < 50){
                handler.postDelayed(this, 20);
            } else {
                setClickable(true);//When done
            }
            count[0]++;
        }
    };
    handler = new Handler();
    handler.postDelayed(run, 10);
}

When running on my Samsung Galaxy S4 mini, it's working juste fine. But for instance, it does not work on the Wiko Highway 4G or on an emulator 1080x1920 and I can't understand why.

When I say that's not working : The view appears and grows but when it grows, every little view that was here before the postDelayed stays there. And when I try to make them disappear by tapping on it, it shrinks well but all the other bigger views (before postDelayed) stay there too.

If you do not understand there, you will on the timer below.

In the meantime, I got a very simple timer like this :

final java.util.Timer t = new java.util.Timer();
            t.scheduleAtFixedRate(new TimerTask() {
                @Override
                public void run() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if(termine){
                                t.cancel();
                            }

                            if(seconds == 0){
                                vCoul.setText(String.valueOf(minutes) + ":00");
                            } else if (seconds < 10) {
                                vCoul.setText(String.valueOf(minutes) + ":0" + String.valueOf(seconds));
                            } else {
                                vCoul.setText(String.valueOf(minutes) + ":" + String.valueOf(seconds));
                            }

                            seconds -= 1;

                            if(seconds == -1){
                                seconds = 59;
                                minutes=minutes-1;
                            }

                        }
                    });
                }
            }, 0, 1000);

But every second, the new time is overlapping the former one.

Sorry for the long post, thanks in advance for your answer!

1

There are 1 answers

0
La masse On BEST ANSWER

I figured this out some months ago but I hope this answer will help others. I didn't put any background in the Activity so on most of samsung devices, there were no issues since Samsung handle just fine the no background activities.

Though, on several Wiko and Archos devices, you have to put a background (like background:#000000) so that you can move views smoothly upon it.