I have an activity with an editText in the middle. When I click on the editText the keyboard appears, and the screen moves so that the editText is just above the keyboard, covering the other stuff that is below.
I don't want to resize or add padding to the layout. I need that the screen scrolls to the top the amount of space that I need to see also the other stuff below. In other words, I'd like to select the position of the editText when the keyboard appears. It would be enough also if the screen scrolls up completely, showing me the bottom of the layout.
I tried to put the layout in a scrollView adding this code on the editText
editText.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //make the view scroll down to the bottom scrollView.scrollTo(0, scrollView.getBottom()); } });
but it doesn't work. Does anyone have an idea? Thank you in advance!
setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //make the view scroll down to the bottom scrollView. scrollTo(0, scrollView. getBottom()); } });
Set fitsSystemWindows = "false" and set android:windowSoftInputMode="adjustResize" in manifest file. Show activity on this post. I have used like this to show the soft keyboard programatically and this is worked for me to prevent the auto resize of the screen while launching the keyboard.
The soft keyboard (also called the onscreen keyboard) is the main input method on Android devices, and almost every Android developer needs to work with this component at some point.
use android:windowSoftInputMode="adjustPan"
"adjustResize"
The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan"
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
For example inn your manifest file:-
<activity android:windowSoftInputMode="adjustPan" android:name=".MainActivity"></activity>
Late answer.But surely it helps anyone.
I had a similar problem once, I resolved using:
android:windowSoftInputMode="adjustResize"
in the AndroidManifest.xml.
If you use a RelativeLayout start with the bottom element that must be hooked to the parent bottom and then hook the other element above the previous.
If you use LinearLayout wrap it in a RelativeLayout and hook the LinearLayout to parentBottom.
In this way when the keyboard pops up you will see the bottom of your layout.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With