0

My project need to insert lots of data,I use scrollview to put them in one page.

Now I want it can scroll the item I press(primary Edittext) to the middle of screen.

I tried to use onFocusChangeListener()+scrollTo() with edittexts,but doesn't work very well.

Is there any better way to do it?

I want to make it act like this

nathanchere
  • 8,008
  • 15
  • 65
  • 86
范植勝
  • 787
  • 2
  • 6
  • 14

1 Answers1

3

Have an onTouchListener for the scrollview.

When the user touches the screen, grab the x and y coordinates and then simply scroll to that point. So scrollview.scrollTo(x,y).

See here for more info

Community
  • 1
  • 1
ilovepjs
  • 622
  • 3
  • 8
  • I had just tried it but doesn't work very well..... It didn't make my edittext in the middle of the screen and I can't scroll it myself anymore..... This is what I just add: `scrollViewPage1.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN){ scrollViewPage1.scrollTo((int)event.getX(), (int)event.getY()); } return true; } });` – 范植勝 Oct 08 '13 at 05:09
  • Try using a `onClickListener` that way you can still scroll ontouch – ilovepjs Oct 08 '13 at 18:54