ScrollViewGenerally nested in one LinearLayout, when you want to use the code operation ScrollViewto scroll to the specified sub- Viewgeneral operation ScrollView.scrollTo(0,View.getTop()), but have you encountered this method when it is invalid?
View.getTop()It is to get the Viewheight relative to the parent container, such as ScrollViewcontaining A LinearLayout, and then A LinearLayoutcontains B LinearLayoutand C LinearLayout, and the TextViewcontrol is a LinearLayoutchild control of C. If you want to ScrollViewscroll to LinearLayoutthe TextViewcontrol in C , it ScrollView.scrollTo(0,TextView.getTop())will be invalid if you use it directly .
As TextView.getTop()it is equal to its distance C LinearLayoutheight of the top, if you want ScrollViewto scroll to the TextViewoffice but also coupled with C LinearLayoutdistance A LinearLayoutfrom the top, so it should be ScrollView.scrollTo(0,CLinearLayout.getTop()+TextView.getTop()).