Original
Today in the downturn when you hit the view of the four get function is a bit special, the specific problems encountered, after repeated testing and find information, pits as follows:
1, why do I sometimes use GetLeft (), GetRight (), GetTop (), Getbottom () The result they get is 0?
A: This may be the case when the program was just started, when the program started to draw the view, you immediately use the code to capture the above values. At this point, because the view is just beginning to draw, you will get 0.
To verify what I said above:
New thread, using the Thread.Sleep (long int) function to delay a period of time before using get, will not be 0.
2, why did I get the wrong value? For example, I set the height= "30DP" or 30dip of a control, and then use Getbottom (), do not get 30?
A: Unit problem. We're invoking the value of the four get function above the view, but it's a pixel, which is PX,
Conversion formula:
DP = (int) (px/1.5 + 0.5), DP is the same as dip.
How do 3,top, bottom and the other 2 compare?
A, the left of the view, top, right, the value of bottom is relative to its parent view, see figure.
Top and left are calculated directly, and the other 2 are as follows: drawings transferred from the network
right = left + width;
Bottom = top + height;
About Android View.getleft (), GetRight (), GetTop (), Getbottom () some doubts (pits) solution