Joel Martinez
Joel Martinez

Reputation: 47751

Properly Scrolling an EditText into view when focused

I've got an EditText, which is ultimately inside of a ScrollView. I've implemented a comment feature which takes you to a new activity, and automatically places focus in the edit text so that the user can immediately start writing his comment.

Unfortunately, it doesn't quite scroll the edittext into view, as you can see in the screenshot below:

Improper Scrolling

I would like to see something more like this, where the EditText comes completely into view (see below). I already looked at the android:WindowSoftInputMode, and it seems like the default values should work ... and indeed, it does mostly work because it does scroll, just not enough.

What I'd like to see

So is there anything I can do to get the desired behavior? Thanks!

Upvotes: 6

Views: 5423

Answers (2)

B.B.
B.B.

Reputation: 954

You could also try to programatically use this on the onCreate() method of you activity.

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

"SOFT_INPUT_ADJUST_PAN" adjustment option is set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible.

Upvotes: 3

san
san

Reputation: 1835

is your min SDK 3? check this

Hope you have tried android:windowSoftInputMode="adjustPan" and check this.

I would give this a go.

Upvotes: 3

Related Questions