问题
I am adding the objects into the horizontal scrollview dynamically and when i add the code below works fine to move extreme right, now the problem is when i try to scroll back to left side via swapping finger the code below again runs and horizontal scrollview scrolls to the right corner again, its a bit annoying, anyone has some alternate solution, I ve tried the
Postdelayed()
but it doesnt work properly for me
ViewTreeObserver viewTreeObserver = hScrollView.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// interestedInView is ready for size and position
// queries because it has been laid out
hScrollView
.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
});
}
Regards MGD
回答1:
is your layoutlistener there to scroll your view all the way to the right when your scrollview is created? If so you should then remove the event listener inside your onGlobalLayout function, otherwise it will scroll right whenever it gets laid out.
来源:https://stackoverflow.com/questions/9414035/horizontal-scrollview-full-scroll-focus-right-with-viewtreeobserver