Search code examples
javaandroidandroid-custom-view

custom view not working until I touch the screen


I'm developing an android app in which I've created my own timers view , when I start showing the view on the screen (Even when I change the screen orientation) nothing is in position :

enter image description here

But as soon as I touch the screen every view take it's place...

enter image description here

See the attached pictures to understand more the problem. Can anyone help me please ?


Solution

  • The problem is about width and height of the view. As I understood, the view uses some value that is equal to zero while launching to draw the circle. But it really needed to use the other value (that calculates later).

    This is reather popular problem: onCreate .. onPause methods do not know its own sizes and window sizes.

    Solution: is to create your own observer that execute some code after the activity will know its sizes.

    Here you know read wonder samples to fix similar issues. https://stackoverflow.com/a/24035591/1979882