Reason: This is a very interesting bug view.getheight (), get the height incredibly and we think not the same, this is a bug from the Xlistview, just started thinking is Scroller did not execute, after one hours of debugging, found that the reason is here, View.getheight (), the height returned is not the same as the true height. Solution: The original code
public int getvisiableheight () {return mcontainer.getheight ();}
After the fixed code:
public int getvisiableheight () {return mcontainer.getlayoutparams (). Height;}
Why is it? Let's take a look at the log.
02-12 18:15:49.774:e/windows (5761): Mcontainer.getheight (): 15702-12 18:15:49.774:e/windows (5761): Mcontainer.getlayoutparams (). height:28402-12 18:15:49.774:e/windows (5761): Mcontainer.getheight (): 15702-12 18:15:49.774:e/windows (5761): Mcontainer.getlayoutparams (). height:28402-12 18:15:49.774:e/windows (5761): Mcontainer.getheight (): 15702-12 18:15:49.774:e/windows (5761): Mcontainer.getlayoutparams (). height:28402-12 18:15:49.884:e/windows (5761): Mcontainer.getheight (): 24702-12 18:15:49.884:e/windows (5761): Mcontainer.getlayoutparams (). height:240
As you can see, there are two big gaps, why? This is mainly because of the computational problem. Mcontainer.getlayoutparams (). Height is a fixed value that you set relative to the parent control. and Mcontainer.getheight () The source code is written like this
Public final int getheight () { return mbottom-mtop; }
The bottom minus the top, it can be calculated, but this process is unreliable, because of the multithreading problem, when we handle Ontouchevent UI thread has not been refreshed, UI thread and ontouchevent is the same thread, do not believe themselves blocked under try to know, The View.getheight () we get is definitely the wrong data, and Getlayoutparams (). Height is a fixed value, so it must be the value when the view is refreshed.
Android does not mess with view.getheight () (especially UI line thread)