android - How to programmatically scroll an HorizontalScrollView -
i have horizontalscrollview
contains relativelayout
. layout empty in xml, , populated java in oncreate.
i scroll view somewhere in middle of relativelayout
, way larger screen.
i tried mhorizscrollview.scrollto(offsetx, 0);
doesn't work. don't know what's wrong this.
i post code, not relevant. matters done programatically (has :s), , initial position of horizontalscrollview
has set programmatically.
thanks reading. please tell me if need more details or if not clear enough.
i found if extend
horizontalscrollview
, override onlayout
, can cleanly scroll, after super call onlayout
:
myscrollview extends horizontalscrollview { protected void onlayout (boolean changed, int l, int t, int r, int b) { super.onlayout(changed, l, t, r, b); this.scrollto(wherever, 0); } }
edit: scrolling start or end can use:
this.fullscroll(horizontalscrollview.focus_right/focus_left);
instead of
this.scrollto(wherever, 0);
Comments
Post a Comment