标签:
public int getVisiableHeight() { return mContainer.getHeight(); }FIXED后的代码:
public int getVisiableHeight() { return mContainer.getLayoutParams().height; }
02-12 18:15:49.774: E/Windows(5761): mContainer.getHeight():157 02-12 18:15:49.774: E/Windows(5761): mContainer.getLayoutParams().height:284 02-12 18:15:49.774: E/Windows(5761): mContainer.getHeight():157 02-12 18:15:49.774: E/Windows(5761): mContainer.getLayoutParams().height:284 02-12 18:15:49.774: E/Windows(5761): mContainer.getHeight():157 02-12 18:15:49.774: E/Windows(5761): mContainer.getLayoutParams().height:284 02-12 18:15:49.884: E/Windows(5761): mContainer.getHeight():247 02-12 18:15:49.884: E/Windows(5761): mContainer.getLayoutParams().height:240
public final int getHeight() { return mBottom - mTop; }底部减去顶部,确实可以计算出来,但是这个过程不可靠,原因就在于多线程问题了,当我们处理onTouchEvent的时候UI线程还没有刷新,UI线程和onTouchEvent是同一个线程,不信自己阻塞下试试就知道了,这时候我们得到的View.getHeight()肯定是个错误的数据,而
Android不能乱用的View.getHeight()(尤其是UI线程里)
标签:
原文地址:http://blog.csdn.net/windowsxp2014/article/details/43765311