自定义视图无法工作,直到我触摸屏幕
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 :
我正在开发一个Android应用程序,我在其中创建了自己的定时器视图,当我开始在屏幕上显示视图时(即使我更改了屏幕方向)也没有任何位置:
But as soon as I touch the screen every view take it's place...
但是当我触摸屏幕时,每个视图都会占据它的位置......
See the attached pictures to understand more the problem. Can anyone help me please ?
请参阅附图以了解更多问题。有人可以帮我吗?
1 个解决方案
#1
1
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.
这是reather流行的问题:onCreate .. onPause方法不知道自己的大小和窗口大小。
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
在这里你知道阅读奇迹样本来解决类似的问题。 https://stackoverflow.com/a/24035591/1979882