0
我有一個視圖,我需要獲取它在屏幕上的頂部和底部位置。所以,我跑瞭如下實驗: 試圖找出什麼打矩形呢,我跑瞭如下實驗如何獲得視圖的矩形外圍
int[] location = { 0, 0 };
myView.getLocationOnScreen(location);
Rect outRect = new Rect();
myView.getHitRect(outRect);
然後打印並得到
outRect.top = 18
outRect.bottom = 138
location[0] = 216
location[1] = 387
我期待outRect.top
和location[1]
是相同。
那麼,如何獲得矩形視圖的頂部和底部位置?
檢查http://stackoverflow.com/questions/5730240/android-get-bounding-rectangle-of-a-view – Ranjit