. . . .
private void initScrollView() {
if (this.selectedInfoView == null) {
return;
}
ScrollView scrollView = (ScrollView)this.getView().findViewById(R.id.scrollView);
LinearLayout linearLayout = null;
if (this.selectedInfo instanceof Info0) {
linearLayout = (LinearLayout)this.getView().findViewById(R.id.linearLayout0);
} else {
assert(this.selectedInfo instanceof Info1);
linearLayout = (LinearLayout)this.getView().findViewById(R.id.linearLayout1);
}
Rect rect = new Rect();
Rect linearLayoutRect = new Rect();
Rect scrollViewRect = new Rect();
selectedInfoView.getHitRect(rect);
linearLayout.getHitRect(linearLayoutRect);
scrollView.getDrawingRect(scrollViewRect);
int correct_expected_bottom_y = linearLayoutRect.top + rect.bottom;
int dy = correct_expected_bottom_y - scrollViewRect.bottom;
if (dy > 0) {
scrollView.scrollBy(0, dy);
}
}
getLocationInWindow, getLocationOnScreen getLocalVisibleRect. .
(x, y - , )
--------------------
| | (?, 120) <-- correct expected bottom y
| | (0, 146) <-- from getLocationInWindow/ getLocationOnScreen
| | (0, 0 - 360, 72) <-- from getLocalVisibleRect
--------------------
| | (?, 193) <-- correct expected bottom y
| | (0, 219) <-- from getLocationInWindow/ getLocationOnScreen
| | (0, 0 - 360, 72) <-- from getLocalVisibleRect
--------------------
| | (?, 266) <-- correct expected bottom y
| | (0, 292) <-- from getLocationInWindow/ getLocationOnScreen
| | (0, 0 - 360, 72) <-- from getLocalVisibleRect
--------------------
| | (?, 339) <-- correct expected bottom y
| | (0, 365) <-- from getLocationInWindow/ getLocationOnScreen
| | (0, 0 - 360, 72) <-- from getLocalVisibleRect
--------------------
| | (?, 485) <-- correct expected bottom y
| [not visible] | (0, 511) <-- from getLocationInWindow/ getLocationOnScreen
| | (0, 413 - 360, 485) <-- from getLocalVisibleRect
--------------------
getLocationInWindow
26 , . , , 26 = 146 - 120. , ActionBar StatusBar.
getLocationOnScreen
, getLocationInWindow
getLocalVisibleRect
, , . , . , y (485), y.