There is a scrollview in it a table of buttons. How do I scroll the scrollview to a button that is outside the visible scrollview area ?

Ex.

ScrollView scrollView = new ScrollView(this); ....//Ρ‚ΡƒΡ‚ ΠΌΡ‹ ΠΊΠ°ΠΊΠΈΠΌ Ρ‚ΠΎ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ надобавляли ΠΊΠ½ΠΎΠΏΠΎΠΊ Π² scrollView .... //ΠΈ Π΅ΡΡ‚ΡŒ ΠΊΠ½ΠΎΠΏΠΊΠ° button, которая ΡƒΠΆΠ΅ находится Π² scrollView; 
  • In Khmlki all add up ... =) - Gorets
  • not an option, the addition should be danamicheskim, buttons more than 100 pieces - andreich

2 answers 2

You need to make a scrollTo() before the button, and this should be done via ScrollView.post() - that is, you will send a message to the window system that will be scrolled after the content is displayed.

 PostScroller ps = new PostScroller(myScrollView, 0, pos); //pos - позиция ΠΊΠ½ΠΎΠΏΠΊΠΈ myScrollView.post(ps); class PostScroller implements Runnable { private View view; private int x, y; PostScroller(View view, int x, int y) { this.view = view; this.x = x; this.y = y; } public void run() { view.scrollTo(x, y); } } 
  • this is understandable, but how can I get the position of the button, the snag is all in it - andreich
 int top = view.getTop(); scrollView.scrollTo(0, top); 
  • Explain what it will give in solving the problem? - 0xdb