edittext inside scrollview, how to scroll to edittext when it gets the focus
simply do this:
scrollView.smoothScrollTo(yourEditTextView.getLeft(), yourEditTextView.getTop())
or if you want this to happen automatically on focus:
yourEditTextView.onFocusChangeListener = View.OnFocusChangeListener { view, hasFocus ->
if (hasFocus) scrollView.smoothScrollTo(view.left, view.top)
}
java code
EditText dwEdit = (EditText) findViewById(R.id.DwEdit);
dwEdit.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
if (view.getId() ==R.id.DwEdit) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()&MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
xml code
<EditText
android:id="@+id/DwEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="10"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
android:inputType="textCapSentences">
</EditText>
First get the x/y coordinates of your Edittext using View.getLocationOnScreen (int[] location) ( After the method returns, the array contains the x and y location in that order)
OR
This links helps you find the views coordinates - https://stackoverflow.com/a/2761184/28557
Then
scrollView.scrollTo(x, y);
hope this helps