I have a scrollview layout with many ViewsStubs and these views stubs are inflated (displayed) depending on the user actions like.....answering the 1st questions makes the 2nd question and answer field(editText) appear
my problem is after answering the 1st question and clicking submit, the next question is made visible but the answer field is hidden under the soft keyboard...user cannot see what he is typing.
what i want is any newly displayed editText/spinner/checkbox must appear at the top of the screen (dynamically scroll to these views).
how to achieve this??
Using the following layout should move the bottom EditText up when the soft keyboard is displayed (call view.setVisibility(true) at some point):
Take my code as example for you, You can do something like following: Make XML as:
And then code:
[1] Get device's screen resolution: Height, Width
[2] Take onFocusChange of your EditText
[3] In that, if your EditText gets focus then
[4] Get that EditText's Bottom, if that Bottom is greater then (ScreenHeight / 3) then
[5] Scroll Your_ScrollView to (left, (ScreenHeight/3));
You can try the requestRectangleOnScreen method to make sure your view is visible. See: http://developer.android.com/reference/android/view/View.html#requestRectangleOnScreen%28android.graphics.Rect%29
In your layout, you can try some of the following things:
1) set the attribute android:fillViewPort="true"
2) set the weight of your edit text to "1" (assuming no other object has a weight of 1)
3) Is your scrollview encompassing all your textviews/edittexts? It might be worth trying to surround your entire layout within the scrollview with that fillViewPort attribute.
this is a pretty good link for scrollviews and their complexity:
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/